Sie sind auf Seite 1von 3

#include<stdio.

h>
#include<conio.h>
#include<stdlib.h>
void swap(int *a, int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
int partition(int a[],int l,int r)
{
int p,i,j;
p=l;
i=l+1;
j=r;
while(i<=j)
{
while(a[i]<=a[p] && i<=r)
i++;
while(a[j]>a[p] && j>=l)
j--;
if(i<=j)
swap(&a[i],&a[j]);
}
swap(&a[p],&a[j]);
return j;

}
void quicksort(int a[],int l, int r)
{
int s;
if(l<r)
{
s=partition(a,l,r);
quicksort(a,l,s-1);
quicksort(a,s+1,r);
}
}
int main()
{
int i,n,l,r,a[10];
printf("enter the array size\n");
scanf("%d",&n);
printf("enter the elements of the array\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
quicksort(a,0,n-1);
printf(" THE SORTED ARRAY IS \n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
getch();
}

Das könnte Ihnen auch gefallen