-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeapInteractive.pde
More file actions
41 lines (36 loc) · 970 Bytes
/
HeapInteractive.pde
File metadata and controls
41 lines (36 loc) · 970 Bytes
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
public class HeapInteractive extends InteractiveFrame implements DataStructureInteractive {
private Heap<State> nodesInQueue;
HeapInteractive(Scene scene) {
super(scene);
reset();
setShape("display");
}
void reset() {
nodesInQueue = new Heap<State>();
}
void add(Object obj) {
State state = (State) obj;
nodesInQueue.put(state);
}
void remove() {
nodesInQueue.remove();
}
void display(PGraphics pg) {
pg.pushStyle();
pg.background(100);
pg.strokeWeight(1);
pg.stroke(082E00);
int side = 20;
pg.fill(0);
pg.textSize(12);
pg.text("Heap:",-100, side - side/3);
pg.textSize(8);
for(int i = 1; i <= nodesInQueue.size(); i++) {
pg.fill(#058B00);
pg.rect(i*side+2*i-72, 0, side, side);
pg.fill(#FF9100);
pg.text(""+nodesInQueue.get(i).cost+","+nodesInQueue.get(i).node.nodeId,i*side + 2*i + side/3 - 74, side - side/3);
}
pg.popStyle();
}
}