Skip to content

Commit

Permalink
Update Queues.java
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme authored Sep 28, 2019
1 parent a47f796 commit cfc26a8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions DataStructures/Queues/Queues.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* 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 {
/**
Expand Down Expand Up @@ -53,7 +52,8 @@ public Queue(int size) {
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;
Expand All @@ -64,9 +64,8 @@ public boolean insert(int x) {
*
* @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];
Expand Down Expand Up @@ -99,7 +98,7 @@ public int peekRear() {
* @return true if the queue is empty
*/
public boolean isEmpty() {
return (nItems == 0);
return nItems == 0;
}

/**
Expand All @@ -108,7 +107,7 @@ public boolean isEmpty() {
* @return true if the queue is full
*/
public boolean isFull() {
return (nItems == maxSize);
return nItems == maxSize;
}

/**
Expand Down

0 comments on commit cfc26a8

Please sign in to comment.