Update Queues.java

This commit is contained in:
Yang Libin 2019-09-28 20:54:35 +08:00 committed by GitHub
parent a47f796764
commit cfc26a865e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,6 @@ package DataStructures.Queues;
* The elements that are added first are the first to be removed.
* New elements are added to the back/rear of the queue.
*
* @author Unknown
*/
class Queue {
/**
@ -53,7 +52,8 @@ class Queue {
public boolean insert(int x) {
if (isFull())
return false;
rear = (rear + 1) % maxSize; // If the back of the queue is the end of the array wrap around to the front
// If the back of the queue is the end of the array wrap around to the front
rear = (rear + 1) % maxSize;
queueArray[rear] = x;
nItems++;
return true;
@ -64,9 +64,8 @@ class Queue {
*
* @return the new front of the queue
*/
public int remove() { // Remove an element from the front of the queue
public int remove() {
if (isEmpty()) {
System.out.println("Queue is empty");
return -1;
}
int temp = queueArray[front];
@ -99,7 +98,7 @@ class Queue {
* @return true if the queue is empty
*/
public boolean isEmpty() {
return (nItems == 0);
return nItems == 0;
}
/**
@ -108,7 +107,7 @@ class Queue {
* @return true if the queue is full
*/
public boolean isFull() {
return (nItems == maxSize);
return nItems == maxSize;
}
/**