-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertex.java
More file actions
118 lines (92 loc) · 1.78 KB
/
Copy pathVertex.java
File metadata and controls
118 lines (92 loc) · 1.78 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.util.List;
import java.util.LinkedList;
class Vertex<T> implements Comparable<T>{
T data;
int id;
Status visited;
List<Edge<T>> edges;
Vertex<T> parent;
int key;
public Vertex(int id, T data){
this.id = id;
this.data = data;
visited = Status.Unvisited;
edges = new LinkedList<Edge<T>>();
parent = null;
key = Integer.MAX_VALUE;
}
public int get_id(){
return id;
}
public void set_id(int id){
this.id = id;
}
public List<Edge<T>> get_edge_list(){
return this.edges;
}
public Status get_visited(){
return visited;
}
public void set_visited(Status v){
this.visited = v;
}
public T get_data(){
return data;
}
public void set_data(T data){
this.data = data;
}
public int get_key(){
return key;
}
public void set_key(int key){
this.key = key;
}
public Vertex<T> get_parent(){
return this.parent;
}
public void set_parent(Vertex<T> v){
this.parent = v;
}
@Override
public boolean equals(Object obj){
if(obj == null){
return false;
}
if(getClass() != obj.getClass()){
return false;
}
final Vertex other = (Vertex) obj;
if(this.data == other.data){
return true;
}
return false;
}
@Override
public int hashCode(){
int hash = 5;
hash = 59*hash + (this.data==null?0:this.data.hashCode());
return hash;
}
@Override
public int compareTo(Object obj) throws ClassCastException{
if(!(obj instanceof Vertex)){
throw new ClassCastException("A Vertex object is expected.");
}
final Vertex other = (Vertex) obj;
int result = -1;
if(this.key==other.key){
result = 0;
}else if(this.key>other.key){
result = 1;
}else{
result = -1;
}
return result;
}
@Override
public String toString(){
return this.data.toString();
}
}
enum Status {Unvisited, InProgress, Visited}