Question: (c) Write (in Java) a method replacekey in the MaxHeap class with the signature: following public void replaceKey (Integer oldKey, Integer newKey) The method will
(c) Write (in Java) a method replacekey in the MaxHeap class with the signature: following public void replaceKey (Integer oldKey, Integer newKey) The method will replace the first occurrence of oldKey with the newKey, and restore the Max-Heap property after the change. If the oldKey does not exist in the heap, the method prints an appropriate message and returns without changing the heap. Example: Suppose our binary heap object (bh) has the following keys: [ 199164?54132 126 1 119 126 14 2021920 Then the method call: bh.replaceKey (new Integer(54), new Integer(105) should change the keys to: 105 99 42 64 32 286 Note: You can assume that the methods perlocateUp and perlocateDown are already implemented in vour MaxHeap class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
