#include<stdio.h>
#define MAX 1000
int quick(int *a,int l,int r,int length)
{
int counter=0,i;
a[0]=a[l];
while(l<r)
{
while(l<r&&a[0]<=a[r])
r--;
a[l]=a[r];
while(l<r&&a[0]>a[l])
l++;
a[r]=a[l];
}
a[l]=a[0];
printf("Step %d: ",++counter);
for(i=1;i<length;i++)
printf("%d ",a[i]);
printf("%d\n",a[length]);
return l;
}
void quicksort(int *a,int l,int r,int length) //快速排序
{
int p;
if(l<r)
{
p=quick(a,l,r,length);
quicksort(a,l,p-1,length);
quicksort(a,p+1,r,length);
}
}
void heap(int *a,int length,int i)
{
int s=i,t;
if(2*i<=length&&a[2*i]>a[s])
s=2*i;
if(2*i+1<=length&&a[2*i+1]>a[s])
s=2*i+1;
if(s!=i)
{
t=a[i];
a[i]=a[s];
a[s]=t;
heap(a,length,s);
}
}
void heapsort(int *a,int length) //堆排序
{
int i,t,counter=0,k=length;
for(i=length/2; i>=1; i--)
heap(a,length,i);
while(length>1)
{
t=a[1];
a[1]=a[length];
a[length]=t;
heap(a,--length,1);
printf("Step %d: ",++counter);
for(i=1;i<k;i++)
printf("%d ",a[i]);
printf("%d\n",a[k]);
}
}
void insertsort(int *a,int length) //插入排序
{
int i,j,t,k,counter=0;
if(length==1)
{
printf("Step %d: %d\n",++counter,a[1]);
return;
}
for(i=2; i<=length; i++)
{
t=a[i];
for(j=i-1; j>0&&a[j]>=t; j--);
for(k=i-1; k>=j+1; k--)
a[k+1]=a[k];
a[k+1]=t;
printf("Step %d: ",++counter);
for(k=1;k<length;k++)
printf("%d ",a[k]);
printf("%d\n",a[length]);
}
}
int main()
{
int n,i;
int a[MAX];
while(scanf("%d",&n)&&n)
{
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
quicksort(a,1,n,n);
}
return 0;
}
2019-07-17 22:49:34