You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
546 B
41 lines
546 B
#include<stdio.h>
|
|
int a[10000],n;
|
|
void quicksort(int left,int right)
|
|
{
|
|
int i,j,t,m;
|
|
if(left>right)
|
|
return;
|
|
m=a[left];
|
|
i=left;
|
|
j=right;
|
|
while(i!=j)
|
|
{
|
|
while(a[j]>=m&&i<j)
|
|
j--;
|
|
while(a[i]<=m&&i<j)
|
|
i++;
|
|
if(i<j)
|
|
{
|
|
t=a[i];
|
|
a[i]=a[j];
|
|
a[j]=t;
|
|
}
|
|
}
|
|
a[left]=a[i];
|
|
a[i]=m;
|
|
quicksort(left,i-1);
|
|
quicksort(i+1,right);
|
|
return;
|
|
}
|
|
int main()
|
|
{
|
|
int i,j;
|
|
scanf("%d",&n);
|
|
for(i=1;i<=n;i++)
|
|
scanf("%d",&a[i]);
|
|
quicksort(1,n);
|
|
for(i=1;i<=n;i++)
|
|
printf("%d ",a[i]);
|
|
return 0;
|
|
}
|