-
Notifications
You must be signed in to change notification settings - Fork 0
/
DirectedGraph.java
105 lines (95 loc) · 2 KB
/
DirectedGraph.java
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
public class DirectedGraph {
public static class EdgeNode {
boolean myVisited;
int myVertex;
int myWeight;
EdgeNode myNext;
/**
* javadoc×¢ÊÍÄÚÈÝ
*
* @since 1.0
* @version 1.1
* @author xxx
*/
public EdgeNode(int vertex, int weight, EdgeNode next) {
myVertex = vertex;
myWeight = weight;
myNext = next;
myVisited = false;
}
}
public class VertexNode {
String myData;
int myCount;
EdgeNode myFirstEdge;
/**
* javadoc×¢ÊÍÄÚÈÝ
*
* @since 1.0
* @version 1.1
* @author xxx
*/
public VertexNode(String data) {
myData = data;
myCount = 0;
myFirstEdge = null;
}
}
VertexNode[] vexList;
/**
* javadoc×¢ÊÍÄÚÈÝ
*
* @since 1.0
* @version 1.1
* @author xxx
*/
public DirectedGraph(String[] filteredWords,
Edge[] edges) {
vexList = new VertexNode[filteredWords.length];
int count = 0;
for (String word : filteredWords) {
vexList[count] = new VertexNode(filteredWords[count]);
count++;
}
for (Edge edge : edges) {
VertexNode src = vexList[edge.mySrc];
src.myFirstEdge = new EdgeNode(edge.myDest,
edge.myWeight, src.myFirstEdge);
src.myCount++;
}
}
/**
* javadoc×¢ÊÍÄÚÈÝ
*
* @since 1.0
* @version 1.1
* @author xxx
*/
public int getIndexOfWord(String word) {
int count = 0;
for (VertexNode vvNode : vexList) {
if (word.equals(vvNode.myData)) {
return count;
} else {
count++;
}
}
return -1;
}
/**
* javadoc×¢ÊÍÄÚÈÝ
*
* @since 1.0
* @version 1.1
* @author xxx
*/
public void resetVisited() {
for (VertexNode vvNode : vexList) {
EdgeNode eeNode = vvNode.myFirstEdge;
while (eeNode != null) {
eeNode.myVisited = false;
eeNode = eeNode.myNext;
}
}
}
}