- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.java
More file actions
Latest commit
73 lines (54 loc) · 1.66 KB
/
Copy pathGraph.java
File metadata and controls
73 lines (54 loc) · 1.66 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
packagegraph_algorithms;
importdata_structures.LinkedList;
importjava.util.function.BiConsumer;
publicabstractclassGraph {
protectedfinalintvertexCount;
protectedfinalbooleandirected;
protectedintedgeCount = 0;
publicGraph(intn, booleandirected) {
vertexCount = n;
this.directed = directed;
}
protectedstaticvoidconstructExampleGraph(Graphgraph) {
graph.addEdge(0, 1, 1);
graph.addEdge(1, 2, 2);
graph.addEdge(2, 3, 3);
graph.addEdge(3, 1, 4);
graph.addEdge(3, 0, 5);
}
publicintgetVertexCount() {
returnvertexCount;
}
publicintgetEdgeCount() {
returnedgeCount;
}
publicvoidaddEdge(intfrom, intto) {
addEdge(from, to, 1);
}
publicvoidaddEdge(intfrom, intto, doublecost) {
_addEdge(from, to, cost);
if (!directed) {
_addEdge(to, from, cost);
}
edgeCount++;
}
protectedabstractvoid_addEdge(intfrom, intto, doublecost);
publicabstractbooleancontainsEdge(intfrom, intto);
publicabstractLinkedList<Integer> outEdges(intvertex); // TODO: Use Dictionary once AVLTree is finished
publicvoidforEachEdge(BiConsumer<Integer, Integer> action) {
for (intu = 0; u < vertexCount; ++u) {
for (intv : this.outEdges(u)) {
action.accept(u, v);
}
}
}
publicabstractdoublecost(intfrom, intto);
publicstaticclassEdge {
intfrom;
intto;
publicEdge(intfrom, intto) {
this.from = from;
this.to = to;
}
}
}