question about quicksort

Posted by davit-datuashvili on Stack Overflow See other posts from Stack Overflow or by davit-datuashvili
Published on 2010-06-02T07:08:33Z Indexed on 2010/06/02 7:13 UTC
Read the original article Hit count: 155

Filed under:

i have write code of quicksort from programming pearls here is code

public class Quick{
 public static   void quicksort(int x[], int l,int u)
 {
  if (l>=u)
 return ;
int t=x[l];
int  i=l;
int  j=u;
do
{
  i++;         

} while (i<=u && x[i]<t);
do
{
 j--;
  if (i>=j) break;

} while ( x[j]>t);





  swap(x,i,j);
 swap(x, l,j);

quicksort(x, l,j-1);
quicksort(x,  j+1,u);



}
public static void main(String[]args){
 int x[]=new int[]{55,41,59,26,53,58,97,93};
 quicksort(x,0,x.length-1);
 for (int i=0;i<x.length;i++){
  System.out.println(x[i]);
}



}

public static void swap(int x[], int i,int j){

 int s=x[i];
x[i]=x[j];
x[j]=s;
}

}

but it does not work here is output

59
41
55
26
53
97
58
93

any idea?

© Stack Overflow or respective owner

Related posts about algorithm