Question: In this part of the assignment, you will implement a Priority Queue. We have given you an interface, PriorityQueue.java and some starter code for your
In this part of the assignment, you will implement a Priority Queue. We have given you an interface, PriorityQueue.java and some starter code for your implementation in Binary- Heap.java. Do not modify the PriorityQueue interface. We have given you the private class, HeapData, that holds data and priority together. You may add additional functionality to this class as you see fit. For simplicity, you may assume that Strings inserted into the heap are unique, but the heap should support duplicate priorities. You may create helper functions as needed. When implementing the BinaryHeap, we recommend that you use indexing that starts at 1 to make parent/child calculations easier.
There are eight functions that we expect you to implement in BinaryHeap:
BinaryHeap(): The default constructor for BinaryHeap. It should instantialize an empty Heap.
BinaryHeap(int startArray): The default constructor for BinaryHeap. It should instantialize an empty Heap where the array is of size startArray
boolean isEmpty(): This function returns true if the heap is empty and false otherwise.
int size(): This function returns the current number of items in the heap.
String findMin(): This function returns the item of smallest priority in the heap. It should not remove that item from the heap. If the heap is empty, it should return null.
void insert(String data, int priority): This function adds the String, priority pair into the heap. Utilize the private class HeapData to store this pair. If the array is full when an insert is called, you must resize the array to accommodate the new data.
String deleteMin(): This function should return and remove the item of smallest priority in the heap. Objects of duplicate priority may dequeue in any order. If the heap is empty, it should return null.
void makeEmpty(): This function should remove all elements from the heap.
boolean changePriority(String data, int newPri): This element should change the priority of a String in the heap. You may assume that the Strings input into the heap are unique. This function returns true if successful, and false if it is unable to find the String in the heap.
These are the given files:


public class BinaryHeap implements PriorityQueuet private class HeapData private String data; private int priority: protected HeapData(String dat,int pri)t data = dat; priority = pri; protected void changePriority(int newPri) priority = newPri; // Add additional functions here as necessary private HeapDatal] heap; // This should be the array where you store your data, priority pairs. // We recommend that you use an array that starts at index 1 to make the math easier private int size; public BinaryHeap() //TODO BinaryHeap constructor public BinaryHeap(int startArray) //TODO this constructor should set the start size of your heap array to startArray public boolean isEmpty) //TODO implement isEmpty return true; public int size()t //TODO implement size return 0 public String findMin)( //TODO implement findMin return null; public void insert (String data, int priority)4 //TODO implement insert public String deleteMin() //TODO implement deleteMin return null; public void makeEmpty()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
