/* 6(b). W.A.P. to sort the elements of an array of size 'n' using recursive quick sort. */
#include<stdio.h>
#include<conio.h>
void QuickSort(int a[],int low,int high)
{
    int temp,flag=0,key,i,j;
    if (low < high)
    {
        key = a[low];
        i = low+1;
        j = high;
        while (1)
        {
            while (a[i] <= key) i++;
            while (a[j] > key) j--;
                if (i < j)
               {
                    temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
                else
                {
                    flag = 1;
                    temp = a[low];
                    a[low] = a[j];
                    a[j] = temp;
                }
                if (flag)
                    break;
        }
        QuickSort(a,low,j-1);
        QuickSort(a,j+1,high);
      }
}
void main()
{
    int i,n,a[10];
    clrscr();
    printf("Enter no. of elements : ");
    scanf("%d",&n);
    printf("\nEnter %d elements : ",n);
    for (i = 0; i < n; i++)        
        scanf("%d",&a[i]);
        QuickSort(a,0,n-1);
        printf("\nThe sorted order :");
    for (i = 0; i < n; i++)    
            printf("\n%d",a[i]);
            getch();
}
/* OUTPUT
Enter no. of elements : 5
Enter 5 elements : 432 234 2 543 23
The sorted order :
2
23
234
432
543
*/