Question: 12.2. In the heap. java program the insert() method inserts a new node in the heap and ensures the heap condition is preserved. Write a


12.2. In the heap. java program the insert() method inserts a new node in the heap and ensures the heap condition is preserved. Write a toss () method that places a new node in the heap array without attempting to maintain the heap condi- tion. (Perhaps each new item can simply be placed at the end of the array.) Then write a restoreHeap() method that restores the heap condition through- out the entire heap. Using toss(o) repeatedly followed by a single restoreHeap() is more efficient than using insert() repeatedly when a large amount of data must be inserted at one time. See the description of heapsort for clues. To test your program, insert a few items, toss in some more, and then restore the heap
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
