-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircular_Queue.java
More file actions
90 lines (90 loc) · 2.28 KB
/
Circular_Queue.java
File metadata and controls
90 lines (90 loc) · 2.28 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//package Queue;
//
//public class Circular_Queue {
//
// public static class Queue{
// static int size;
// static int[] arr;
// static int rear;
// static int front;
//
// public Queue(int n){
// arr = new int[n];
// size = n;
// rear = -1;
// front = -1;
// }
//
// // Empty function
// public static boolean isEmpty(){
// return rear == -1 && front == -1;
// }
//
// // Full function
// public static boolean isFull(){
// return (rear+1)%size == front;
// }
//
// // add at end
// public static void add(int data){
// if (isFull()){
// System.out.println("Full Queue!");
// return;
// }
// rear = (rear + 1)%size;
// arr[rear] = data;
// }
//
// // remove from front
// public static int remove(){
// if (isEmpty()){
// return -1;
// }
//
// int start = arr[front];
// if (front == rear){
// front = -1;
// rear = -1;
// }else {
// front = (front + 1) % size;
// }
// return start;
// }
//
// // peek the first element
// public static int peek(){
// if (isEmpty()) return -1;
//
// return arr[front];
// }
//
// // display
// public static void display(){
// if (isEmpty()) {
// System.out.println("Empty Queue");
// return;
// }
// System.out.print("front -> ");
// for (int i=0; i<=rear; i++){
// System.out.print(arr[i] + " -> ");
// }
// System.out.print("End");
// }
// }
//
// public static void main(String[] args) {
// int n = 5;
// Queue.Array_Implementation.Queue que = new Queue.Array_Implementation.Queue(n);
//
// que.display();
//
// que.add(1);
// que.add(2);
// que.add(3);
// que.add(4);
// que.add(5);
// que.add(6); // full queue
//
// que.display();
// }
//}