当前位置: 代码迷 >> C语言 >> 关于链表
  详细解决方案

关于链表

热度:380   发布时间:2006-12-19 16:49:43.0
关于链表

今天学链表有的迷糊
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct STUDENT {char name[20];
float age,chinese,math;
struct STUDENT *next;
};
typedef struct STUDENT STU;
STU *create_list();
void print_list(STU *head);
main()
{

STU *head;
head= create_list();
print_list(head);
}
STU *create_list()
{
STU *head,*p,*q;
char na[20];
head=(STU *)malloc(sizeof(STU));
q=head;
printf("输入数据\n");
scanf("%s",na);

while (strcmp(na,"over")!=0)
{
p=(STU *)malloc(sizeof(STU));
strcpy(p->name,na);
scanf("%d%f%f",&p->age,&p->chinese,&p->math);
q->next= p;
q = p;
scanf("%s",na);

}
q->next= NULL;
return head;

}
void print_list(STU *head)
{
STU *p;
p=head->next;
while(p!=NULL)
{
printf("%s%d%f%f\n",p->name,p->age,p->chinese,p->math);
p=p->next;
}
}能不能给我注释下

搜索更多相关的解决方案: 链表  

----------------解决方案--------------------------------------------------------
  相关解决方案