-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathQueueExample.java
51 lines (37 loc) Β· 1.47 KB
/
QueueExample.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
package Queue;
public class QueueExample {
public static void main(String[] args) {
{
ArrayQueue<Integer> queue = new ArrayQueue<>(3);
queue.enqueue(5);
queue.enqueue(3);
System.out.println(queue.size()); // 2
System.out.println(queue.dequeue()); // 5
System.out.println(queue.isEmpty()); // false
System.out.println(queue.dequeue()); // 3
System.out.println(queue.isEmpty()); // true
System.out.println(queue.dequeue()); // null
queue.enqueue(7);
queue.enqueue(9);
System.out.println(queue.peek()); // 7
queue.enqueue(4);
System.out.println(queue.dequeue()); // 7
}
{
LinkedQueue<Integer> queue = new LinkedQueue<>();
queue.enqueue(5);
queue.enqueue(3);
System.out.println(queue.size()); // 2
System.out.println(queue.dequeue()); // 5
System.out.println(queue.isEmpty()); // false
System.out.println(queue.dequeue()); // 3
System.out.println(queue.isEmpty()); // true
System.out.println(queue.dequeue()); // null
queue.enqueue(7);
queue.enqueue(9);
System.out.println(queue.peek()); // 7
queue.enqueue(4);
System.out.println(queue.dequeue()); // 7
}
}
}