Implement a Priority Queue. We have given you an interface, PriorityQueue.java and some starter code for your
Question:
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:
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:
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.
Artificial Intelligence A Modern Approach
ISBN: 978-0137903955
2nd Edition
Authors: Stuart J. Russell and Peter Norvig