-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathQueueArrayDemo.java
43 lines (39 loc) · 1.4 KB
/
QueueArrayDemo.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
package com.houarizegai.datastructure.queue.array;
public class QueueArrayDemo {
public static void main(String[] args) {
arrayQueueDemo();
}
private static void arrayQueueDemo() {
QueueArray<Integer> queue = new QueueArray(3);
queue.add(10);
queue.add(19);
queue.add(1);
queue.print();
queue.display();
System.out.println("Remove: " + queue.remove());
queue.print();
queue.display();
System.out.println("Remove: " + queue.remove());
queue.print();
queue.display();
queue.add(15);
queue.add(3);
queue.print();
queue.display();
System.out.println("Remove: " + queue.remove());
System.out.println("Remove: " + queue.remove());
queue.print();
queue.display();
queue.add(77);
queue.print();
queue.display();
System.out.printf("queue[%d]=%d\n", 0, queue.get(0));
System.out.printf("queue[%d]=%d\n", 1, queue.get(1));
System.out.printf("queue[%d]=%d\n", 2, queue.get(2));
System.out.printf("queue[%d]=%d\n", 2, queue.get(-1));
System.out.println("Remove: " + queue.remove());
System.out.println("Remove: " + queue.remove());
System.out.println("Poll: " + queue.poll());
System.out.println("Remove: " + queue.remove()); // Null pointer exception: Queue is empty
}
}