mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 12:11:28 +08:00
@ -53,9 +53,7 @@ class Queue {
|
|||||||
public boolean insert(int x) {
|
public boolean insert(int x) {
|
||||||
if (isFull())
|
if (isFull())
|
||||||
return false;
|
return false;
|
||||||
if (rear == maxSize - 1) // If the back of the queue is the end of the array wrap around to the front
|
rear = (rear + 1) % maxSize; // If the back of the queue is the end of the array wrap around to the front
|
||||||
rear = -1;
|
|
||||||
rear++;
|
|
||||||
queueArray[rear] = x;
|
queueArray[rear] = x;
|
||||||
nItems++;
|
nItems++;
|
||||||
return true;
|
return true;
|
||||||
@ -72,9 +70,7 @@ class Queue {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int temp = queueArray[front];
|
int temp = queueArray[front];
|
||||||
front++;
|
front = (front + 1) % maxSize;
|
||||||
if (front == maxSize) //Dealing with wrap-around again
|
|
||||||
front = 0;
|
|
||||||
nItems--;
|
nItems--;
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user