package tree1;

import java.util.*;

public class q1 {

public staticint []a={2,5,7,0,9,7,1,3,44,21};

public static void main(String[]args)

{

System.out.println("quick sorting:");

quick(a,0,9);

System.out.println("after sorting:");

for(int i=0;i<10;i++)

System.out.print(a[i]+" ");

}

public static void quick(int[] a,int left,int right)

{

int dp;

if(left<right)

{

dp=partition(a,left,right);

quick(a,left,dp-1);

quick(a,dp+1,right);

}

}

public static int partition(int[]a,int left,int right)

{//left=0 right=9

int lo,hi,pivot,t;

pivot=a[left];

lo=left-1;//lo=-1

hi=right+1;//hi=10

while(lo+1!=hi)

{

if(a[lo+1]<=pivot)

lo++;

else if(a[hi-1]>pivot)

hi--;

else

{

t=a[lo+1];

a[++lo]=a[hi-1];

a[--hi]=t;

}

}

a[left]=a[lo];

a[lo]=pivot;

return lo;

}

}