From b73757e4bb0c30314b63c046cd92770e935ade2d Mon Sep 17 00:00:00 2001 From: Akhil <31859863+hailK11@users.noreply.github.com> Date: Sat, 16 Feb 2019 20:24:39 +0530 Subject: [PATCH] Update PriorityQueues.java Include condition to check if the queue is full when inserting values into the queue --- DataStructures/Queues/PriorityQueues.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/DataStructures/Queues/PriorityQueues.java b/DataStructures/Queues/PriorityQueues.java index acb6b552..3eb74ecf 100644 --- a/DataStructures/Queues/PriorityQueues.java +++ b/DataStructures/Queues/PriorityQueues.java @@ -37,6 +37,10 @@ class PriorityQueue{ public void insert(int value){ if(nItems == 0){ queueArray[0] = value; + nItems++; + } + else if(isFull()){ //does not insert value when the queue is full + System.out.println("Queue is full"); } else{ int j = nItems; @@ -45,8 +49,8 @@ class PriorityQueue{ j--; } queueArray[j] = value; //Once the correct position is found the value is inserted + nItems++; } - nItems++; } /** @@ -120,4 +124,4 @@ public class PriorityQueues{ //As you can see, a Priority Queue can be used as a sorting algotithm } -} \ No newline at end of file +}