Professional Documents
Culture Documents
Dsapackage Queue
Dsapackage Queue
int[] arr;
int topOfQueue;
int size;
int start;
this.size = size;
this.topOfQueue = -1;
start = -1;
}//end of method
if(arr==null) {
}else if (isQueueFull()) {
}else {
initializeStartOfArray();
if (topOfQueue+1 == size) { //if top is already at last cell of array, then reset it to
first cell
topOfQueue=0;
}else {
topOfQueue++;
arr[topOfQueue] = value;
}//end of method
if (start == -1) {
start = 0;
}//end of method
if (isQueueEmpty()) {
} else {
System.out.println("\n---------------------------------------------");
System.out.println("Before Dequeue..");printArray();
}else if (start+1 == size) { //if start has reached end of array, then start again
from 0
start=0;
}else {
start++;
System.out.println("After Dequeue..");printArray();
System.out.println("---------------------------------------------");
}//end of method
if (topOfQueue == -1)
return true;
else
return false;
}//end of method
if (topOfQueue+1 == start) { //If we have completed a circle, then we can say that
Queue is full
return true;
}else if ((start==0) && (topOfQueue+1 == size)) { //Trivial case of Queue being full
return true;
}else {
return false;
}//end of method
public void peekOperation() {
if (!isQueueEmpty()) {
System.out.println(arr[start]);
}else {
}//end of method
arr = null;
}//end of method
System.out.println("Array now...");
System.out.print(arr[i]+" ");
}//end of method
}//end of class