//快速排序算法
细节挺多的
#include<stdio.h>
#include<string.h>
typedef struct word{
int length;
int index;
}w;
void swap(int *a,int *b){
int t;
t = *a;
*a = *b;
*b = t;
}
int partition(w a[],int left,int right){
//选择主元,不断调整其他元素的位置使得左小右大
while(left<right){
while(left<right&&a[left].length<=a[right].length){
right--;
}
if(left<right){
swap(&a[left].length,&a[right].length);
swap(&a[left].index,&a[right].index);
left++;
}
while(left<right&&a[left].length<=a[right].length){
swap(&a[left].length,&a[right].length);
swap(&a[left].index,&a[right].index);
right--;
}
}
return left;
}
void QuickSort(w a[],int left,int right){
if(left<right){
int mid = partition(a,left,right);
QuickSort(a,left,mid-1);
QuickSort(a,mid+1,right);
}
}
void QSort(w a[],int n){
QuickSort(a,0,n-1);
}
int main()
{
w a[20];
char c[20][11];
int i=0;
gets(c[i]);
while(c[i][0]!='#'){
a[i].length = strlen(c[i]);
a[i].index = i;
i++;
gets(c[i]);
}
int n=i;
QSort(a,i);
for(i=0;i<n;i++){
printf("%s ",c[a[i].index]);
}
}