(Solved):A. Write a Java method replaceKey in the BinaryHeap class with the following signature: public void replaceKey(Integer oldKey, Integer newKey) The method will replace the first occurrence of oldKey… View Answer…

 

Question

A. Write a Java method replaceKey in the BinaryHeap class with the following signature:

public void replaceKey(Integer oldKey, Integer newKey)

The method will replace the first occurrence of oldKey with the newKey and restore the Min-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. Suppose our binary heap object (bh) has the following keys:

5, 10,

Scroll to top