From cfc26a865ee0b9b772fe7df8e49ce4ca57f0ac0a Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Sat, 28 Sep 2019 20:54:35 +0800 Subject: [PATCH] Update Queues.java --- DataStructures/Queues/Queues.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/DataStructures/Queues/Queues.java b/DataStructures/Queues/Queues.java index 01b20b9a3..f9bb42e4a 100644 --- a/DataStructures/Queues/Queues.java +++ b/DataStructures/Queues/Queues.java @@ -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; } /**