-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiGraphInterface.java
More file actions
75 lines (70 loc) · 2.57 KB
/
Copy pathDiGraphInterface.java
File metadata and controls
75 lines (70 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package DiGraph_A5;
/**
* COMP 410
*
* Make your class and its methods public!
* Don't modify this file!
* Begin by creating a class that implements this interface.
*
*/
public interface DiGraphInterface {
/*
Interface: A DIGRAPH will provide this collection of operations:
addNode
in: unique id number of the node (0 or greater)
string for name
you might want to generate the unique number automatically
but this operation allows you to specify any integer
both id number and label must be unique
return: boolean
returns false if node number is not unique, or less than 0
returns false if label is not unique (or is null)
returns true if node is successfully added
addEdge
in: unique id number for the new edge,
label of source node,
label of destination node,
weight for new edge (use 1 by default)
label for the new edge (allow null)
return: boolean
returns false if edge number is not unique or less than 0
returns false if source node is not in graph
returns false if destination node is not in graph
returns false is there already is an edge between these 2 nodes
returns true if edge is successfully added
delNode
in: string
label for the node to remove
out: boolean
return false if the node does not exist
return true if the node is found and successfully removed
delEdge
in: string label for source node
string label for destination node
out: boolean
return false if the edge does not exist
return true if the edge is found and successfully removed
numNodes
in: nothing
return: integer 0 or greater
reports how many nodes are in the graph
numEdges
in: nothing
return: integer 0 or greater
reports how many edges are in the graph
topoSort:
in: nothing
return: array of node labels (strings)
if there is no topo sort (a cycle) return null for the array
if there is a topo sort, return an array containing the node
labels in order
*/
// ADT operations
boolean addNode(long idNum, String label);
boolean addEdge(long idNum, String sLabel, String dLabel, long weight, String eLabel);
boolean delNode(String label);
boolean delEdge(String sLabel, String dLabel);
long numNodes();
long numEdges();
String[] topoSort();
}