Can i get help with the missing code "insert code here" java language :
Can i get help with the missing code "insert code here" java language :
code :
import java.util.Comparator;
import java.util.NoSuchElementException;
public class PriorityQueue
{
/* attributes */
private int currentSize; // Number of elements in heap
private PriorityQueueNode [ ] PQ; // The priority queue array
private static final int DEFAULT_CAPACITY = 2>>14;
private Comparator<? super PriorityQueueNode> cmp; // object to compare to instances of PriorityQueueNode
/* default constructor */
public PriorityQueue( )
{
currentSize = 0;
cmp = null;
PQ = new PriorityQueueNode [DEFAULT_CAPACITY + 1];
}
/* getter methods for attributes */
public int getSize( )
{
return currentSize;
}
public boolean add( PriorityQueueNode x )
{
// insert code here
}
public PriorityQueueNode remove( )
{
// insert code here
}
private void percolateDown( int hole )
{
// insert code here
}
public void display() //
{
// insert code here
}
/* auxiliary methods: you may use the below methods to help you write your code, if necessary */
private int compare( PriorityQueueNode lhs, PriorityQueueNode rhs )
{
if(cmp == null)
{
return ((Comparable)lhs).compareTo(rhs);
}
else
{
return cmp.compare(lhs, rhs);
}
}
public void swapReferences(PriorityQueueNode [] a, int p, int q)
{
PriorityQueueNode tmp = a[p];
a[p] = a[q];
a[q] = tmp;
}
private void doubleArray( )
{
PriorityQueueNode [ ] newArray;
newArray = new PriorityQueueNode[ PQ.length * 2 ];
for( int i = 0; i < PQ.length; i++ )
newArray[ i ] = PQ[ i ];
PQ = newArray;
}
public PriorityQueueNode element( )
{
if(isEmpty())
{
throw new NoSuchElementException();
}
return PQ[1];
}
public void clear( )
{
currentSize = 0;
}
public boolean isEmpty()
{
return currentSize==0;
}
}
![In PriorityQueue.java, write code for the following new functions:
1. public boolean add( PriorityQueueNode x )
This function adds a new node x to the priority queue. The node is added to
the heap by comparison of the rating attribute. It involves the “percolate
up" process and returns true when finished.
2. public PriorityQueueNode remove( )
This function removes the minimum element of the priority queue and returns
it. It involves a call to percolateDown ( int hole ).
3. private void percolateDown ( int hole )
This function takes the position of the next available hole in the priority queue
and uses it to bubble the elements through the heap until the heap property is
restored.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F13f42eda-4233-4463-985e-07142dfa1519%2Fd3a303eb-af27-45cc-a7bb-320bb6434461%2Fw0491fs_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)