$24
Instruction
Submit your answer to this question via PC^2 under your account by the posted due time. No late submissions will be accepted. Note that homework is opened-book, but no outside assistance is permitted.
Problem
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]