1. One approach is to store the complete binary tree of the heap in two separate arrays. One array, called priority, contains the priorities of the nodes. Another array, called data, contains the data...


1. One approach is to store the complete binary tree of the heap in two separate arrays. One array, called priority, contains the priorities of the nodes. Another array, called data, contains the data of the nodes. For example, priority[0] and data[0] contain the priority and data of the root of the heap.


With this idea, we can write a priority queue implementation, as shown here:





The size instance variable indicates how much of the arrays is currently being used. The constructor is responsible for allocating the initial arrays. The method that adds a new element to the priority queue may need to increase the size of these arrays.


Nov 21, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here