c语言 建立单向链表,C语言建立单向链表

这是一个存储数据的结构体;也是链表结点的数据结构如下:

#include

#include

#include

#define size sizeof(struct student)

struct student {

char name[30];

int number;

float score[4];

struct student *next;

};

struct student *head;//头节点;

struct student *create()

{

struct student *ps,*pend;

head=NULL;

pend=ps;

ps=malloc(size);

printf("please input the data:name,number,englist,math,computer,polic. \n");

scanf("%s%d%f%f%f%f",ps->name,&ps->number,&ps->score[0],&ps->score[1],&ps->score[2],&ps->score[3]);

while(strcmp(ps->name,"0")!=0 && ps->number!=0 )

{

if(head==NULL)

head=ps;

else

pend->next=ps;

pend=ps;

ps=malloc(size);

printf("please input the data:\n");

scanf("%s%d%f%f%f%f",ps->name,&ps->number,&ps->score[0],&ps->score[1],&ps->score[2],&ps->score[3]);

}

pend->next=NULL;

free(ps);

return head;   //返回非常重要的头节点;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值