Possible Duplicate:
what is mistake in this code
i have following code from algorithm in c++
public class improved_quicksort {
public static final int m=10;
public static int partition(int a[],int l,int r){
int i=l-1;
int j=r;
int v=a[r];
while (true){
while(a[++i]<v);
while (a[--j]>v) if (j==i) break;
if (i>=j) break;
exch(a,i,j);
}
exch(a,i,r);
return i;
}
public static void quicksort(int a[],int l,int r){
if ((r-l)<m) return;
exch (a,(l+r)/2,r-1);
compex(a,l,r-1);
compex(a,l,r);
compex(a,r-1,r);
int i=partition(a,l+1,r-1);
quicksort(a,l,i-1);
quicksort(a,i+1,r);
}
public static void compex(int a[],int i,int j){
if (a[i]<a[j]){
int t=a[i];
a[i]=a[j];
a[j]=t;
}
}
public static void main(String[] args) {
int a[]=new int[]{12,10,23,21,11,34,56,38,50,40,60,76,67};
quicksort(a,0,a.length-1);
for (int i=0;i<a.length;i++){
System.out.println(a[i]);
}
}
public static void exch(int a[],int i,int j){
int k=a[i];
a[i]=a[j];
a[j]=k;
}
}
but result is:
67
10
11
23
12
34
76
38
50
40
60
56
21