COU *create_form()
{
COU *head,*tail,*p;
int num,stime,ttime;
int etime,score,term;
char name[20],kind[10];
int size=sizeof(COU);
head=tail=NULL;
printf("输入选修课程信息:\n");
scanf("%d%s%s%d%d%d%d%d",&num,name,kind,&stime,&ttime,&etime,&score,&term);
while(num!=0)
{
p=(COU *)malloc(size); //开辟结构体大小的空间
p->num=num; //给结构体中num变量赋值
strcpy(p->name,name); //将name字符串的内容复制到结构体变量name
strcpy(p->kind,kind);
p->stime=stime;
p->ttime=ttime;
p->etime=etime;
p->score=score;
p->term=term;
if(head==NULL) //表头指针指为空
{
head=p; //则将表头指针指向刚赋完值的一个完整结构体的数据域
}
else //表头指针不为空则说明有指向的数据内容
{
tail->next=p;//表尾指针域指向下一个内容的结构体数据域
}
tail=p;
scanf("%d%s%s%d%d%d%d%d",&num,name,kind,&stime,&ttime,&etime,&score,&term);
}
tail->next=NULL;
return head;
}
void* BasicInsert(COU *subj)
{
COU *ptr2;
if(head==NULL)//头结点为空
{
head=subj;
head->next=NULL;
}
else
{
for(ptr2=head;ptr2;ptr2=ptr2->next) //从链表头开始找,找到目前最后一个结点
{
if(ptr2->next==NULL) //若当前ptr2是链表最后一个结点
{
ptr2->next=subj; //在链表尾增加一个结点subj
subj->next=NULL; //将新结点的指针域置为空结束链表
break;
}
}
}
return head;
}
typedef struct courses //定义结构体叫作COU,在后面就可以直接使用
{
int num; //课程编号
char name[30]; //课程名称
char kind[20]; //课程性质
int stime; //总学时
int ttime; //授课学时
int etime; //实验或上机学时
int score; //学分
int term; //开课学期
struct courses *next;
}COU;
COU *head=NULL;