Вы находитесь на странице: 1из 2

visit-www.Codes2u.

com
#include<stdio.h>
#include<conio.h>
int q,a[50],key;
void quick(int a[],int p,int r)
{
if(p<r)
{ q=split(a,p,r);
quick(a,p,q-1);
quick(a,q+1,r);
}
}
int split(int a[],int p,int r)
{ int j;int t; int i;
j=r; i=p+1;
key=a[p] ;
while(i<=j)
{
while(a[i]<key)
{ i++; }
while(a[j]>key)
{ j--;}
if(i<j)
{t=a[i];
a[i] =a[j];
a[j]=t;
}
}
t=a[p];
a[p]=a[j];
a[j]=t;
return(j);
}
void main()
{ int i,n ;
printf("\n enter the size of array ");
scanf("%d",&n);
printf("\n enter the array to be sorted");
for(i=1;i<=n;i++)
{ scanf("%d",&a[i]);
}
quick(a,1,n);

printf(" \nthe array after sorting is");


for(i=1;i<=n;i++)
{ printf(" %d",a[i]);
}
getch();
}

Вам также может понравиться