#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int fast(int *p,int m,int n)
{
if(m<n)
{
int i,j,a=n,b=m,temp,counter;
srand(time(0));
i=rand()%n+m;
do
{
counter=0;
j=a;
while(*(p+i)<=*(p+j)&&i<j)
{
j--;
}
if(i<j)
{
temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
i=j;
a=j;
counter++;
}
j=b;
while(*(p+i)>=*(p+j)&&i>j)
{
j++;
}
if(i>j )
{
temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
i=j;
b=j;
counter++;
}
}while(counter>0);
fast(p,m,i-1);
fast(p,i+1,n);
}
return 0;
}
int main()
{
int n,i=0,*p;
scanf("%d",&n);
getchar();
p=(int *)malloc(n*sizeof(int));
do
{
scanf("%d",p+i);
i++;
}while(getchar()==' ');
fast(p,0,n-1);
for(i=0;i<n-1;i++)
{
printf("%d ",*(p+i));
}
printf("%d\n",*(p+i));
free(p);
return 0;
}```