Update PriorityQueues.java

Include condition to check if the queue is full when inserting values into the queue
This commit is contained in:
Akhil 2019-02-16 20:24:39 +05:30 committed by GitHub
parent 46bbfaa0e8
commit b73757e4bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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++;
}
/**