Quick Sort In C..( C Program for quick Sort)

#include<stdio.h>
void quicksort(int b[25],int f,int l)
{
    int i, j, pivot,temp;
    if(f<l)
    {
        pivot=f;
        i=f;
        j=l;
        while(i<j)
        {
            while(b[i]<=b[pivot]&&i<l)
                i++;
            while(b[j]>b[pivot])
                j--;
            if(i<j)
            {
                temp=b[i];
                b[i]=b[j];
                b[j]=temp;
            }
        }
        temp=b[pivot];
        b[pivot]=b[j];
        b[j]=temp;
        quicksort(b,f,j-1);
        quicksort(b,j+1,l);
    }
}
int main()
{
    int i,n,a[25];
    printf("Enter How many elements:");
    {
        scanf("%d",&n);
    }
    printf("Enter %d elements:\n",n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    quicksort(a,0,n-1);
    printf("The Sorted Order is: ");
    for(i=0; i<n; i++)
    {
        printf("\n%d",a[i]);
    }
    return 0;
}


*** Input && Output ***



Post a Comment

0 Comments