# QuickSort

**Java Code To Illustrate QuickSort:**

package quicksort;

import edu.princeton.cs.introcs.*;

public class QuickSort

{

public static void display(int a[])

{

for (int k=0;k<a.length;k++) System.out.print(a[k] + ” “);

System.out.println();

}

public static int Partition(int A[], int p, int r)

{

int pivot = A[r];

int i = p-1;

int temp;

for (int j=p;j<r;j++)

{

if (A[j]<=pivot)

{

i++;

temp = A[i];

A[i] = A[j];

A[j] = temp;

}

}

temp = A[r];

A[r] = A[i+1];

A[i+1] = temp;

return i+1;

}

public static int HoarePartition(int A[], int p, int r)

{

int i = p;

int j = r;

int x = A[p];

int temp;

while (i<j)

{

while(A[j]>=x && j>p) –j;

while(A[i]<=x && i<r) ++i;

if(i<j)

{

temp = A[i];

A[i] = A[j];

A[j] = temp;

}

}

temp = A[p];

A[p] = A[j];

A[j] = temp;

return j;

}

public static void quicksort(int A[],int p, int r)

{

if…

View original post 55 more words

Posted on June 27, 2013, in Algorithms, Java and tagged QuickSort in Java. Bookmark the permalink. Leave a comment.

## Leave a comment

## Comments 0