Question: How can i trace this code by hand? public static > void heapSort ( T [ ] ar ) { ArrayList list = new ArrayList

How can i trace this code by hand?
public static > void heapSort(T[] ar)
{
ArrayList list = new ArrayList();
for (int i =0; i ar.length; ++i)
add(list, ar[i]);
}
public static > void add(ArrayList list, T t)
{
list.add(t);
if (list.size()==1)
return;
int curentIndex = list.size()-1;
while (curentIndex >0
&& list.get(curentIndex).compareTo(list.get((curentIndex -1)/2))>0)
{
T temp = list.get((curentIndex -1)/2);
list.set((curentIndex -1)/2, list.get(curentIndex));
list.set(curentIndex, temp);
curentIndex =(curentIndex -1)/2;
if ( curentIndex ==3)
{
System.out.println(list.get(curentIndex));
return;
}
}
}
public static void main(String... ar)
{
Integer[] ar3={10,2,20,1,12,8,3,56,1};
heapSort(ar3);
}
How can i trace this code by hand? public static

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!