-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueInteractive.pde
41 lines (36 loc) · 950 Bytes
/
QueueInteractive.pde
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 QueueInteractive extends InteractiveFrame implements DataStructureInteractive {
private LinkedList<Integer> nodesInQueue;
QueueInteractive(Scene scene) {
super(scene);
reset();
setShape("display");
}
void reset() {
nodesInQueue = new LinkedList<Integer>();
}
void add(Object obj) {
Node node = (Node) obj;
nodesInQueue.add(node.nodeId);
}
void remove() {
nodesInQueue.poll();
}
void display(PGraphics pg) {
pg.pushStyle();
pg.background(100);
pg.strokeWeight(1);
pg.stroke(082E00);
int side = 20;
pg.fill(0);
pg.textSize(14);
pg.text("Queue:",-100, side - side/3);
pg.textSize(10);
for(int i = 0; i < nodesInQueue.size(); i++) {
pg.fill(#058B00);
pg.rect(i*side+2*i-50, 0, side, side);
pg.fill(#FF9100);
pg.text(""+ nodesInQueue.get(i),i*side + 2*i + side/3 - 50, side - side/3);
}
pg.popStyle();
}
}