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.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here