-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.java
78 lines (67 loc) · 1.6 KB
/
Node.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
import java.util.*;
/**
* A node in the graph.
*
* @author Shalin Shah
* Email: [email protected]
*/
public class Node implements Comparable
{
public int value;
public int degree = 0;
public LinkedHashSet list;
/** Creates a new instance of Node */
public Node(int v)
{
value = v;
list = new LinkedHashSet();
}
/*
* compareTo method of the interface Comparable
*/
public int compareTo(Object o)
{
Node obj = (Node)o;
if(this.value == obj.value)
{
return 0;
}
if(this.degree < obj.degree)
return 1;
else if(this.degree > obj.degree)
return -1;
else
return 0;
}
/*
* Is the passed in object equal to this object?
*/
public boolean equals(Object obj)
{
Node o = (Node)obj;
if(o.value == this.value)
return true;
return false;
}
/* Add a sibling */
public void addEdge(int ev)
{
list.add(new Integer(ev));
}
/*
* Canonical String representation of this Node
*/
public String toString()
{
return "Value=" + value + " Degree=" + degree;
}
/* Hash Code */
public int hashCode()
{
StringBuffer buffer = new StringBuffer("");
buffer.append(value);
buffer.append(" ");
buffer.append(degree);
return new String(buffer.toString()).hashCode();
}
}