Untitled
raw download clone
C
views 13
,
size 818 b
#include<stdio.h>
#include<time.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,k;
    if(low>=high) return;
    key=low;
    i=low+1;
    j=high;
    while(i<=j)
    {
        while(a[i]<=a[key]) i++;
        while(a[j]>a[key]) j--;
        if(i<j) Exch(&a[i],&a[j]);
    }
    Exch(&a[j],&a[key]);
    QuickSort(a,low,j-1);
    QuickSort(a,j+1,high);
}
void main()
{
    int n,a[1000],k;
    printf("\nEnter how many numbers");
    scanf("%d",&n);
    printf("\n enter numbers");
    for(k=1;k<=n;k++)
    {
        a[k]=rand();
        printf("%d\t",a[k]);
    }

    QuickSort(a,0,n);
    printf("sorted numbers\n");

    for(k=1;k<=n;k++)
    {
        printf("%d\t",a[k]);
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.