Merge pull request #67 from AnupKumarPanwar/master

QuictSort.c and QiSort.c are same. Deleted QiSort.c
This commit is contained in:
Anup Kumar Panwar 2017-10-03 16:49:26 +05:30 committed by GitHub
commit 891bc9f671

View File

@ -1,50 +0,0 @@
#include <stdio.h>
void swap(int *a,int *b)
{
int t;t=*a;*a=*b;*b=t;
}
void qiksort(int a[],int n,int l,int r)
{int pivot = a[l];
int p1=l+1,p2=r;
if (r>l)
{
while(p2>=p1)
{if (a[p1]>pivot && a[p2]<pivot)
{
swap(&a[p1],&a[p2]);
p1++;p2--;
}
else
{if (a[p1]<=pivot)
{
p1++;
}
if (a[p2]>=pivot)
{p2--;}
}
}
swap(&a[p2],&a[l]);
qiksort(a,n,l,p2-1);
qiksort(a,n,p2+1,r);
}
}
int main()
{
int n,*a,i;
scanf("%d",&n);
a = (int*)malloc(n*sizeof(int));
for (i=0;i<n;i++)
{scanf("%d",a+i);}
qiksort(a,n,0,n-1);
printf("\n\n");
for (i=0;i<n;i++)
{printf("%d",a[i]);}
return 0;
}