Given an integer array with no duplicates. A priority queue building on this array is defined as follow: The root is the maximum number in the array The left subtree and right subtree are the heaps of the subarray divided by the root number. Construct the heap by the given array. Example Given [16 14 10 8 7 9 3 2 4 1] the priority queue visualized by this heap is:
Write a program that builds a priority queue on input array and output an array representation of the heap.
Sample input
2,4,1
16,14,10,8,7,9,3,2,4,1
Sample output
The array representation of the heap is [4 2 1]
The array representation of the heap is [16 14 10 8 7 9 3 2 4 1]
Reviews
There are no reviews yet.