package SwapSort;
import java.util.Arrays;
public class QuickSort {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] data={49,38,65,97,76,13,27,50};
System.out.println(Arrays.toString(quickSort(data,0,7)));
}
public static int[] quickSort(int[] data,int low, int high){
if(low<high){
int pivot=partition(data,low,high);
quickSort(data,low, pivot-1);
quickSort(data,pivot+1,high);
}
return data;
}
public static int partition(int[] data, int low, int high) {
// TODO Auto-generated method stub
int base=data[low];
while(low<high){
while(low<high&&base<=data[high]){
--high;
}
data[low]=data[high];
while(low<high&&base>=data[low]){
++low;
}
data[high]=data[low];
}
System.out.println(low+" "+high);
data[low]=base;
System.out.println(Arrays.toString(data));
return low;
}
}