Circular Queue
Circular Queue
Circular Queue
int[] Q;
int N;
int n = 0;
int front = -1, rear = -1;
CAQ() {
N = 10;
n = 0;
Q = new int[N];
}
if (n == 0) {
System.out.println("no data");
} else {
// for (int i = 0; i < N; i++) {
//
// System.out.print(" " + Q[i]);
// }
if (rear >= front) {
for (int j = front; j <= rear; j++) {
System.out.print(" " + Q[j]);
}
}
if (rear < front) {
for (int h = front; h < N; h++) {
System.out.print(" " + Q[h]);
}
for (int k = 0; k <= rear; k++) {
System.out.print(" " + Q[k]);
}
}
System.out.println();
System.out.println("front points to " + front + " index and " +
Q[front] + " value");
System.out.println("rear points to " + rear + " index and " + Q[rear] +
" value");
System.out.println("total values are " + n + " values");
System.out.println();
} else if (n == 1) {
temp = Q[front];
// Q[front] = 0;//The following line shows the code to remove the last
element of the array hence turning it to 0
front--;
rear--;
n--;
}
return temp;
}