-
Notifications
You must be signed in to change notification settings - Fork 0
/
PriorityQueueNode.java
60 lines (48 loc) · 1.26 KB
/
PriorityQueueNode.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
import java.util.ArrayList;
import java.util.Arrays;
/* Custom Priority Queue class with ArrayList<Node> for A* */
public class PriorityQueueNode {
ArrayList<Node> pl;
public PriorityQueueNode(){
pl = new ArrayList<Node>();
}
public void add(Node n) {
pl.add(n);
pl.sort((a,b)->(a.f() - b.f()));
}
public boolean isEmpty() {
return pl.isEmpty();
}
public Node poll() {
Node t = pl.get(0);
pl.remove(0);
return t;
}
public boolean contains(Node g) {
for(Node n : pl){
if(n.equals(g)) return true;
}
return false;
}
/* swap nodes */
public void swapForLowerValue(Node n){
for (int i = 0; i < pl.size(); i++) {
Node t = pl.get(i);
if(t.equals(n)){
System.out.println("HERE");
pl.remove(i);
this.add(n);
break;
}
}
}
public String toString(){
return Arrays.deepToString(pl.toArray());
}
public int size() {
return pl.size();
}
public Object[] toArray() {
return pl.toArray();
}
}