0

Hello, BTW the program compiles. Im trying to change a quick sort program so that it picks a median of three for the pivot instead of the first low number. My code is not running right, can somebody help me out. thanks

```
public class QuickSort{
public static void main(String a[]){
int i;
int array[] = {12,9,4,99,120,1,3,10,13};
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++)
System.out.print( array[i]+" ");
System.out.println();
quick_srt(array,0,array.length-1);
System.out.print("Values after the sort:\n");
for(i = 0; i <array.length; i++)
System.out.print(array[i]+" ");
System.out.println();
System.out.println("PAUSE");
}
public static void quick_srt(int array[],int low, int n){
int swap;
int lo = low;
int hi = n;
if (lo >= n) {
return;
}
//Pivot median of three
int mid = array[(lo + hi) / 2];
if(array[mid] < array[lo]){
swap = array[lo];
array[lo]=array[mid];
array[mid]=swap;
}
if(array[hi] < array[lo]){
swap = array[lo];
array[lo]= array[hi];
array[hi]= swap;
}
if(array[mid] < array[lo]){
swap = array[mid];
array[mid]= array[hi];
array[hi] = swap;
}
swap = array[mid];
array[mid]= array[hi-1];
array[hi-1]= swap;
while (lo < hi) {
while (lo<hi && array[lo] < mid) {
lo++;
}
while (lo<hi && array[hi] > mid) {
hi--;
}
if (lo < hi) {
int T = array[lo];
array[lo] = array[hi];
array[hi] = T;
}
}
if (hi < lo) {
int T = hi;
hi = lo;
lo = T;
}
quick_srt(array, low, lo);
quick_srt(array, lo == low ? lo+1 : lo, n);
}
}
```