Posts

Showing posts from August 11, 2013

Quick Sort Simplest Code

public class Sort {   public static void quick(int a[],int beg, int end){     if(beg<end){         int p=partition(a,beg,end);         quick(a,beg,p-1);         quick(a,p+1,end);     }   } public static int partition(int a[], int beg, int end){     int c[]=new int[a.length],l=beg,r=end,pivot=beg;    //variable declaration     for(int i=beg+1;i<=end;i++){         if(a[i]<a[pivot]) c[l++]=a[i];         else c[r--]=a[i];     }     c[l]=a[pivot];     for(int i=beg;i<=end;i++)         a[i]=c[i];        return l; } public static void main(String[] args){     int a[]={26,19,45,30,34,42,15,18,21,32,36,13,22,33,14,32,42};     int n=a.length;     System.out.println("List Before Sorting:-\n\n"); ...