一个链表问题,请教C高手

来源:百度知道 编辑:UC知道 时间:2024/06/05 13:42:41
请为下列给出的某班级C程序编码员列表,建立一个链表。

姓名 赵达 钱亮 孙立为 王胜利 周学立
出生年月 1983 1984 1980 1983 1981
3 5 1 10 6

说明
① 在上表中,每人为一个节点,节点中有4个成员:姓名、出生年、出生月和指针。然后用指针将每个节点链接起来。
② 节点链接的条件是生日大者在前,小者在后。
③ 最后输出已按顺序排好的并具有5个节点的链表。
排版出错,从重排一下

姓 名 赵达 钱亮 孙立为 王胜利 周学立
出生年月 1983 1984 1980 1983 1981
月 份 3 5 1 10 6

出生年月行,上面为年,下面为月,两者在同一表格中。

#include "stdio.h"
#include <malloc.h>

struct Student
{
char name[20];
int BirthOfYear;
int BirthOfMonth;

}student[5] = {{"钱达",1983,3},{"钱亮",1984,5},{"孙立为",1980,1},{"王胜利",1983,10},{"周学立",1981,6}};

struct List
{
struct Student stu;
struct List *next;
};

struct List* Creat(struct List* head,struct List* p0)//建立链表
{

struct List *p1,*p2;

p1 = head;

if (head == NULL)
{
head = p0;
p0->next = NULL;

}

else
{
/*比较后进行插入*/
while ( (p1->next != NULL) && (p0->stu.BirthOfYear <p1->stu.BirthOfYear || ( (p0->stu.BirthOfYear == p1->stu.BirthOfYear) && (p0->stu.BirthOfMonth < p1->stu.BirthOfMonth))) )
{
p2 = p1;
p1 = p1->next;
}

if (p0->stu.BirthO