-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathVertex.java
More file actions
56 lines (47 loc) · 1.21 KB
/
Vertex.java
File metadata and controls
56 lines (47 loc) · 1.21 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
/**
* Vertex structure of the graph.
*
* @id a name of the vertex.
* @d distance from the source to the current Vertex / timestamp when a vertex is discovered.
* @f timestamp when a vertex is finished.
* @color the color of the vertex
* @p predecessor of the current Vertex
* @neighbors a list storing the adjacent vertices of a vertex.
*/
package graphalgorithms;
import java.util.List;
import java.util.LinkedList;
public class Vertex {
final int id;
int d;
int f;
Color color;
Vertex p;
List<Vertex> neighbors;
public Vertex(int id) {
this.id = id;
this.d = -1;
this.f = -1;
this.color = Color.WHITE;
this.p = null;
this.neighbors = new LinkedList<>();
}
@Override public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || (getClass() != o.getClass())) {
return false;
}
Vertex other = (Vertex) o;
return (id == other.id);
}
@Override public int hashCode() {
int result = 17;
result = result * 31 + id;
return result;
}
@Override public String toString() {
return String.valueOf(id);
}
}