Merge pull request #864 from shellhub/master

optimization
This commit is contained in:
Yang Libin
2019-09-26 09:01:47 +08:00
committed by GitHub

View File

@ -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;
} }