optimization

This commit is contained in:
shellhub 2019-09-25 20:26:48 +08:00
parent 23ca7169e8
commit ef767fc4d5

View File

@ -53,9 +53,7 @@ class Queue {
public boolean insert(int x) {
if (isFull())
return false;
if (rear == maxSize - 1) // If the back of the queue is the end of the array wrap around to the front
rear = -1;
rear++;
rear = (rear + 1) % maxSize; // If the back of the queue is the end of the array wrap around to the front
queueArray[rear] = x;
nItems++;
return true;
@ -72,9 +70,7 @@ class Queue {
return -1;
}
int temp = queueArray[front];
front++;
if (front == maxSize) //Dealing with wrap-around again
front = 0;
front = (front + 1) % maxSize;
nItems--;
return temp;
}