要多快啊,冒泡可以不
typedef struct _student
{
char name[20];
int score;
}student;
void sort(student a[],int n)
{
int i,j,t;
student s;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j].score < a[j+1].score)
{
s = a[j];
a[j] = a[j+1];
a[j+1] = s;
}
}
}
}
void QuickSort(student *arr, int low, int high)
{
if (low < high)
{
int i = low;
int j = high;
student k = arr[low];
while (i < j)
{
while(i < j && arr[j].score >= k.score) // 从右向左找第一个小于k的数
{
j--;
}
if(i < j)
{
arr[i++] = arr[j];
}
while(i < j && arr[i].score < k.score) // 从左向右找第一个大于等于k的数
{
i++;
}
if(i < j)
{
arr[j--] = arr[i];
}
}
arr[i] = k;
// 递归调用
QuickSort(arr, low, i - 1); // 排序k左边
QuickSort(arr, i + 1, high); // 排序k右边
}
}
void main()
{
student stu[50];
int i,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s %d",stu[i].name,&stu[i].score);
}
//sort(stu,n);
QuickSort(stu,0,n-1);
for(i=0;i<n;i++)
printf("%s\t",stu[i].name);
printf("\n");
for(i=0;i<n;i++)
printf("%d\t",stu[i].score);
}