Illustrates the program segment for Quick sort. It uses recursion.
Program 1: Quick Sort
Quicksort(A,m,n)
int A[ ],m,n
{
int i, j, k;
if m
{
i=m; j=n+1; k=A[m]; do
do
do
++i;
while (A[i] < k);
do
--j;
while (A[j] > k);
if (i < j)
{
temp = A[i];
A[i] = A[j];
A[j] = temp;
}
while (i
temp = A[m];
A[m] = A[j];
A[j] = temp;
Quicksort(A,m,j-1);
Quicksort(A,j+1,n);
}
The Quick sort algorithm uses the O(N Log2N) comparisons on average. The performance can be developed by keeping in mind the following points.
1. Switch to a faster sorting scheme such as insertion sort while the sublist size becomes comparatively small.
2. Employ a better dividing element in the implementations.