C语言 我的程序差在哪里? 谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/15 02:19:41
这是我的课程设计 为什么运行不了 有一个错误帮帮我吧 谢谢
#include "stdio.h"
#include "math.h"
#include "string.h"
#include "stdlib.h"
#define TRUE 1
#define FALSE 0
#define LENGTH 2
struct date
{
int day,month,year;
};

struct student_record
{
char name [100];
struct date birthday;
float score;
};
int partions(int l[],int low,int high)
{
int prvotkey=l[low];
l[0]=l[low];
while (low<high)
{
while (low<high&&l[high]>=prvotkey)
--high;
l[low]=l[high];
while (low<high&&l[low]<=prvotkey)
++low;
l[high]=l[low];
}

l[low]=l[0];
return low;
}

void qsort(int l[],int low,int high)
{
int prvotloc;
if(low<high)
{
prvotloc=partions(l,low,high);
qsort(l,low,prvotloc-1);
qsort(l,prvotloc+1,high);
}
}
void quicks

楼主的程序完成的功能是将输入的学生信息进行排序,并输出。可是,在调用排序函数quicksort()时,存在错误,并且在使用自定义的函数qsort()和函数partions()进行排序中,无法分辨是根据学生信息的哪个字段进行排序的,是姓名、学分、还是生日信息。
下面的程序代码片段功能是进行学生信息排序,主要用于代替楼主的函数quicksort()、qsort()和partions(),请将上述函数定义、声明、调用注释。

int cmp(const void *p1, const void *p2)
{
return strcmp(((struct student_record *)p1)->name, ((struct student_record *)p2)->name);
}

并将
quicksort(struct student_record *sps[],int length);
替换为
qsort(students, LENGTH, sizeof(struct student_record), cmp); // 此函数为C库函数