Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello. I just asked this and got a good answer. However, I have another question

ID: 3596553 • Letter: H

Question

Hello. I just asked this and got a good answer. However, I have another question. I am working on a max heap tree with the following code:

I need the output of this tree to be in descending order because I am creating a priority queue. When I plug 0 into the currentIndex value, it works fine. However, as the number passed to currentIndex increases, the values become out of order. I was hoping someone could show me how to write this with the array being put into descending order. Thanks.

public static void increasekey (patientList[] heapList,int currentIndex,int newKey) int temp = 0; if (newkey heapList[currentIndex]-priorityNum) heapList[currentIndex].priorityNumnewKey; while(currentIndex >= 0 && heapList[(currentIndex-1)/21.priorityNum

Explanation / Answer

The Collections.reverseOrder() provides a Comparator that would sort the elements in the PriorityQueue in a the oposite order to their natural order in this case.