-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.java
55 lines (48 loc) · 1.2 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
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
public class Node implements Comparable<Node> {
int color=-1;
int index;
int out_degree=0;
int in_degree=0;
List<Node> in_neighbour = new ArrayList<>();
List<Node> out_neighbour = new ArrayList<>();
List<Node> neighbour = new ArrayList<>();
public boolean add_in_neighbour(Node u) {
if (in_neighbour.add(u)) {
in_degree += 1;
return true;
}
return false;
}
public boolean add_out_neighbour(Node u) {
if (out_neighbour.add(u)) {
out_degree += 1;
return true;
}
return false;
}
public boolean add_neighbour(Node u) {
if (neighbour.add(u)) {
return true;
} else {
return false;
}
}
@Override
public int compareTo(Node o) {
if (this.color > o.color) {
return 1;
} else if (this.color < o.color) {
return -1;
} else {
if (this.index > o.index) {
return 1;
} else {
return -1;
}
}
}
}