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

I am currently writing a java max heap program. Here is my source code: This pro

ID: 3595841 • Letter: I

Question

I am currently writing a java max heap program. Here is my source code:

This program randomly generates 20 patientlist objects with each one having a priority code. When I run this code, I get results in ascending order. The smallest number is in the 0 array postition. I need to reverse this, with the highest number in the 0 position. Is there a way I can tweak this code to give results in descending order?

Thanks.

public static void maxheapify (patientList[] heapList, int userIndex) patientList templist; int left = 2* (userIndex) ; int right = 2*userIndex+1; int largest = 0; if (left heapList[userIndex].priorityMum) largest = left ; else largest = userIndex ; if (right heapList[largest ]-priorityNum) largest = right ; if (largest != userIndex) templList = heapList[userIndex] ; heapList[userIndex] = heapList[largest ; heapList largest ] = tempList ; maxheapify(heapList, largest);

Explanation / Answer

Yes you can do this. You just make a small change in your code. You are comparing the elements with priority.

So just need to change the comparision symbol in the function.

the code is here

if(left <= (sortCount) && heapList[left].priorityNum < heapList[userIndex].priorityNum)
           largest = left;
       else
           largest = userIndex;
       if(right <= (sortCount) && heapList[right].priorityNum < heapList[largest].priorityNum)
           largest = right;

change this peice of code and your task will complete. If you will not get the desired result than give the entire code with main function and all the member functions. Then I will got the any other mistake in the code.