Program
#include <stdio.h>
#include <conio.h>
void Exch(int *p, int *q)
{
int temp = *p;
*p = *q;
*q = temp;
}
void QuickSort(int a[], int low, int high)
{
int i, j, key;
key = low;
i = low;
j = high;
if (low >= high)
return;
while (!(i == j && i == key))
{
if (key == i)
{
while (a[key] < a[j])
j = j - 1;
Exch(&a[key], &a[j]);
key = j;
}
else
{
while (a[i] < a[key])
i = i + 1;
Exch(&a[key], &a[i]);
key = i;
}
}
QuickSort(a, low, key - 1);
QuickSort(a, key + 1, high);
}
int main()
{
printf("******************************");
printf("\n******************************");
printf("\n** Quick Sort Program **");
printf("\n** Created by Sheetal Garg **");
printf("\n** Assistant Professor **");
printf("\n** Phone No:9467863365 **");
printf("\n******************************");
printf("\n******************************\n");
int n, a[6], i, j, temp, key, low, high;
printf("\n Enter How many Numbers: ");
scanf("%d", &n);
printf("\nEnter the array elements\n");
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
QuickSort(a, 0, n - 1);
printf("\n Array after sorting is\n");
for (i = 0; i < n; i++)
printf("%d\t", a[i]);
return 0;
}
Output
****************************** ****************************** ** Quick Sort Program ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** ****************************** ****************************** Enter How many Numbers: 5 Enter the array elements 23 32 12 24 4 Array after sorting is 4 12 23 24 32