c语言 链表相关代码,c语言链表及其相关操作代码.docx

c语言链表及其相关操作代码

链表动态创建#include#include#includestruct Student{char num[10]; //字符串学号char name[10]; //字符串姓名double score; //双精度实型成绩struct Student *next; //用与构建链表指向下一结点};struct Student *creatlinklist()//当成绩项目输入0时,创建链表结束{struct Student *head;struct Student *p1,*p2;int n;n=0;head=NULL;p1=(struct Student *)malloc(sizeof(struct Student));printf("请输入学号姓名和成绩\n");scanf("%s%s%lf",p1->num,p1->name,&p1->score);while(p1->score!=0){if(n==0){head=p1;p2=p1;n++;}else{p2->next=p1;p2=p1;n++;}p1=(struct Student *)malloc(sizeof(struct Student));printf("请输入学号姓名和成绩\n");scanf("%s%s%lf",p1->num,p1->name,&p1->score);}if(head!=NULL)p2->next=NULL;return head;}voidprint_linklist(struct Student *head){struct Student *pi;if(head==NULL){printf("空链表!\n");}else{printf("学号\t姓名\t成绩\n");for(pi=head;pi!=NULL;pi=pi->next){printf("%s\t%s\t%lf\n",pi->num,pi->name,pi->score);}}}int main(){struct Student *head;head=creatlinklist();print_linklist(head);return 0;}/链表查找#include#include#includestruct Student{char num[10]; //字符串学号char name[10]; //字符串姓名double score; //双精度实型成绩struct Student *next; //用与构建链表指向下一结点};struct Student *creatlinklist(){struct Student *head;struct Student *p1,*p2;int n;n=0;head=NULL;p1=(struct Student *)malloc(sizeof(struct Student));printf("请输入学号姓名和成绩\n");scanf("%s%s%lf",p1->num,p1->name,&p1->score);while(p1->score!=0){if(n==0){head=p1;p2=p1;n++;}else{p2->next=p1;p2=p1;n++;}p1=(struct Student *)malloc(sizeof(struct Student));printf("请输入学号姓名和成绩\n");scanf("%s%s%lf",p1->num,p1->name,&p1->score);}if(head!=NULL)p2->next=NULL;return head;}voidprintlinklist(struct Student *head){struct Student *pi;if(head==NULL){printf("空链表!\n");}else{printf("学号\t姓名\t成绩\n");for(pi=head;pi!=NULL;pi=pi->next){printf("%s\t%s\t%lf\n",pi->num,pi->name,pi->score);}}}struct Student * find_linklist_by_name(struct Student *head,char name[]){struct Stud

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值