15. Given the following class header, instance variables, and add method for a H
ID: 3707633 • Letter: 1
Question
15. Given the following class header, instance variables, and add method for a Heap public class Heap { Comparable 1 arr int next-1 public void add(T val throws Exception //verify the array is not full if (next > arr.length-2) 1 expandArray ) arr I++next] val; reHeapUp (next); Complete the code for reHeapuplint index) that was discussed in class and in the book: Note, reHeapUp( int index) is called with an index of next after a node has been added to the tree and the tree needs to be re-prioritized The variable, next, is the index of the last node in the Heap. Your method should be recursive. public void reHeapUp (int index) fExplanation / Answer
The above recursive algorithm should know the index of the current element that may need to shift.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.