Question: let list = { 2 0 , 1 7 , 2 5 , 2 8 , 8 , 1 0 , 2 1 , 3

let list ={20,17,25,28,8,10,21,34,7,19,32,43,11,9,12,23,13,35,18,16,15}
If we were to call partition(list,0,20), what value will be returned?
public static int partition(int[] list, int first, int last){
int pivot = list[first];
int low = first +1;
int high = last;
while(high > low){
while(low <= high && list[low]<= pivot)
low++;
while(low <= high && list[high]> pivot)
high--;
if(high > low){
int temp = list[high];
list[high]= list[low];
list[low]= temp;
}
}
while(high > first && list[high]>= pivot)
high--;
if(pivot > list[high]){
list[first]= list[high];
list[high]= pivot;
return high;
}else
return first;
}

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