-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertex.java
More file actions
64 lines (53 loc) · 1.51 KB
/
Vertex.java
File metadata and controls
64 lines (53 loc) · 1.51 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
import java.util.ArrayList;
public class Vertex implements Comparable<Vertex> {
//value/location of index in start graph
int value;
//ArrayList of vertices connected to this vertex
ArrayList<Integer> edges;
//degree of this vertex
int degree;
//current state of the post office: 1 is open, 0 is undecided, -1 is closed
int state;
//does the vertex have a neighbor that is open?
boolean access;
public Vertex(int i) {
edges = new ArrayList<Integer>();
degree = 0;
state = 0;
value = i;
access = false;}//end method
public void addEdge(int e) {
edges.add(e);
degree++;}//end method
public void removeEdge(int vertToRemove) {
degree--;
edges.remove(Integer.valueOf(vertToRemove));}//end method
public int compareTo(Vertex w) {
if(this.value > w.value) {
return 1;}//end if
else if(this.value < w.value) {
return -1;}//end else if
else {
return 0;}}//end else, method
public Vertex copy() {
Vertex clone = new Vertex(this.value);
clone.state = this.state;
clone.value = this.value;
clone.degree = this.degree;
clone.access = this.access;
for(Integer e: this.edges) {
int x = e.intValue();
Integer i = x;
clone.edges.add(i);}//end for
return clone;}//end method
public int getDegree() {
return degree;};
public int getValue() {
return value;}//end method
public int getState() {
return state;}//end method
public boolean getAccess() {
return access;}//end method
public ArrayList<Integer> getNeighbors() {
return edges;}//end method
}//end class