Question: Rewrite the insertionSort ( ) so that it takes one additional Boolean input to determine sort in ascending order or descending order public void insertionSort

Rewrite the insertionSort() so that it takes one additional Boolean input to determine sort in ascending order or descending order
public void insertionSort(Comparable[] list)
{
for (int index =1; index < list.length; index++)
{
Comparable key = list[index];
int position = index;
// Shift larger values to the right
while (position >0 && key.compareTo((T)list[position-1])<0)
{
list[position]= list[position -1];
position--;
}
list[position]= key;
}
}

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 Databases Questions!