|
4 | 4 | //Link to the concept: (https://en.wikipedia.org/wiki/Circular_buffer)
|
5 | 5 | public class CircularQueue {
|
6 | 6 |
|
7 |
| - public static void main(String[] args) { |
8 |
| - circularQueue cq = new circularQueue(5); |
9 |
| - System.out.println(cq.isEmpty()); |
10 |
| - System.out.println(cq.isFull()); |
11 |
| - cq.enQueue(1); |
12 |
| - cq.enQueue(2); |
13 |
| - cq.enQueue(3); |
14 |
| - cq.enQueue(4); |
15 |
| - cq.enQueue(5); |
16 |
| - |
17 |
| - System.out.println(cq.deQueue()); |
18 |
| - System.out.println(cq.deQueue()); |
19 |
| - System.out.println(cq.deQueue()); |
20 |
| - System.out.println(cq.deQueue()); |
21 |
| - System.out.println(cq.deQueue()); |
22 |
| - System.out.println(cq.isFull()); |
23 |
| - System.out.println(cq.isEmpty()); |
24 |
| - cq.enQueue(6); |
25 |
| - cq.enQueue(7); |
26 |
| - cq.enQueue(8); |
27 |
| - System.out.println(cq.peek()); |
28 |
| - System.out.println(cq.peek()); |
29 |
| - cq.deleteQueue(); |
30 |
| - |
31 |
| - } |
32 |
| -} |
33 |
| - |
34 |
| -class circularQueue { |
35 |
| - |
36 | 7 | int[] arr;
|
37 | 8 | int topOfQueue;
|
38 | 9 | int beginningOfQueue;
|
39 | 10 | int size;
|
40 | 11 |
|
41 |
| - public circularQueue(int size) { |
| 12 | + public CircularQueue(int size) { |
42 | 13 | arr = new int[size];
|
43 | 14 | topOfQueue = -1;
|
44 | 15 | beginningOfQueue = -1;
|
@@ -115,4 +86,30 @@ public void deleteQueue() {
|
115 | 86 | System.out.println("The Queue is deleted!");
|
116 | 87 | }
|
117 | 88 |
|
| 89 | + |
| 90 | + public static void main(String[] args) { |
| 91 | + CircularQueue cq = new CircularQueue(5); |
| 92 | + System.out.println(cq.isEmpty()); |
| 93 | + System.out.println(cq.isFull()); |
| 94 | + cq.enQueue(1); |
| 95 | + cq.enQueue(2); |
| 96 | + cq.enQueue(3); |
| 97 | + cq.enQueue(4); |
| 98 | + cq.enQueue(5); |
| 99 | + |
| 100 | + System.out.println(cq.deQueue()); |
| 101 | + System.out.println(cq.deQueue()); |
| 102 | + System.out.println(cq.deQueue()); |
| 103 | + System.out.println(cq.deQueue()); |
| 104 | + System.out.println(cq.deQueue()); |
| 105 | + System.out.println(cq.isFull()); |
| 106 | + System.out.println(cq.isEmpty()); |
| 107 | + cq.enQueue(6); |
| 108 | + cq.enQueue(7); |
| 109 | + cq.enQueue(8); |
| 110 | + System.out.println(cq.peek()); |
| 111 | + System.out.println(cq.peek()); |
| 112 | + cq.deleteQueue(); |
| 113 | + |
| 114 | + } |
118 | 115 | }
|
0 commit comments