You are on page 1of 2

package sorting;

public class quicksort {


static int array[]={67,1,5,67,1,1,5,5,67,45};
static int low=0;
static int top=9;
static void quick(int low, int top)
{
if(low<top)
{
int s = partition(low,top);
quick(low,s-1);
quick(s+1,top);
}
}
static int partition(int low,int top)
{
int pivot=array[low];
int i=low+1;
int j=top;
while(i<j)
{
while(array[i]<=pivot)
{ if(i<top)
i++;
else
break;
}
while(array[j]>=pivot)
{
if(j>low)
j--;
else
break;
}
if(i<j)
swap(i,j);
}
if(j>low && array[j]<=pivot)
swap(j,low);
return j;
}
static void swap (int i,int j)
{
int temp=array[i];
array[i]=array[j];
array[j]=temp;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
quick(low,top);
System.out.println("sorted array is");
for(int x=0;x<(array.length);x++)
{
System.out.println(array[x]);
}

}
}

You might also like