-
Notifications
You must be signed in to change notification settings - Fork 2
/
QueueNode.java
94 lines (67 loc) · 1.67 KB
/
QueueNode.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Priority Queue Data
public class QueueNode implements Comparable<QueueNode> {
// Byte is an attempt to save space and increase performance
byte current, depth;
// Starts a null because the first Node won't have a parent
QueueNode parent = null;
double weight;
// Constructor for the first node without a parent
public QueueNode(byte current) {
this.current = current;
this.depth = 0;
this.weight = 0;
}
// Contructor for a QueueNode with a parent, current
// info (which is comparable), depth, and distance
public QueueNode(byte current, byte depth, QueueNode parent, double weight) {
this.current = current;
this.depth = depth;
this.parent = parent;
this.weight = weight;
}
// Returns the Current Node
public byte getCurrent() {
return current;
}
// Returns the Depth
public byte getDepth() {
return depth;
}
// Returns the Weight
public double getWeight() {
return weight;
}
// Returns the Parent of the current node
public QueueNode getParent() {
return parent;
}
// Sets the Current Node
public void setCurrent(byte current) {
this.current = current;
}
// Sets the Depth for a Node
public void setDepth(byte depth) {
this.depth = depth;
}
// Sets the weight
public void setWeight(double weight) {
this.weight = weight;
}
// Sets the parent
public void setParent(QueueNode parent) {
this.parent = parent;
}
// Auto Generated because of comparable
@Override
public int compareTo(QueueNode nodeCompare) {
if (nodeCompare.weight > this.weight) {
return -1;
}
else if (nodeCompare.weight < this.weight) {
return 1;
}
else {
return 0;
}
}
}