package lab3;
/**
*
* @author ying
*/
public class No2 {
public static void main(String[] args){
int[] L={8,14,3,9,11,5,10,1,2,6,7,15,12,0,4,13};
SortArray LL=new SortArray(L);
LL.quicksort(0,15);
for(int i=0;i<L.length;i++){
System.out.print(LL.L[i]+” “);
}
System.out.println(“\nNo. of comparation is “+LL.count);
}
/** Creates a new instance of No2 */
}
class SortArray{
public int L[];
public int count=0;
SortArray(int[] L){
this.L=L;
}
public void quicksort(int first,int last){
if(first<last){
int splitpoint=split(first,last);
quicksort(first,splitpoint-1);
quicksort(splitpoint+1,last);
}
}
public int split(int first,int last){
int x=L[first];
int splitpoint=first;
for(int i=first+1;i<=last;i++){
count++;
if(L[i]<x){
splitpoint++;
interchange(splitpoint,i);
}
}
interchange(first,splitpoint);
return splitpoint;
}
public void interchange(int x,int y){
int temp = L[x];
L[x]=L[y];
L[y]=temp;
}
}