为了账号安全,请及时绑定邮箱和手机立即绑定

在挑选出1400分以上的数据构成链表时有问题,求助?

在挑选出1400分以上的数据构成链表时有问题,求助?

C
北云 2017-03-30 17:24:14
建立一个单链表,并使用该链表存储所有学生的信息。假设最初建立的链表名为ListA,你要将链表ListA中成成绩在1400分以上(含1400分)的节点从ListA中删去,并把这些节点插入到新链表ListB中,最后输出链表B#include<stdio.h>#include<stdlib.h> #include<string.h> struct student{ char name[20]; char num[20]; int score; struct student *next;};main(){//构建链表A struct student *head1,*p1,*p2; int m=0,n=0; p1=p2=(struct student*)malloc(sizeof(struct student)); scanf("%s %s %d",p1->name,p1->num,&p1->score); head1=NULL; while(strcmp(p1->name,"#####")!=0) { n++;  if(n==1)  head1=p1;  else  p2->next=p1;  p2=p1;  p1=(struct student*)malloc(sizeof(struct student));  scanf("%s %s %d",p1->name,p1->num,&p1->score); } p2->next=NULL; //链表ListA中成成绩在1400分以上(含1400分)的节点从ListA中删去,并把这些节点插入到新链表ListB中struct student *head2,*q1,*q2; struct student *m1,*m2; m1=head1; m2=head1; while(m2!=NULL) { if(m1->score>=1400){ m++; q1=m1; if(m==1)  {  head2=m1;    q2=m1;}   else  {  q2->next=q1;  q2=q1;  } m2->next=m1->next; } m2=m1; m1=m1->next; } q2->next=NULL;//提取1400以上的数据  //打印1400以上的数据 struct student *node; node=head2; while(node!=NULL) {     printf("%s %s %d\n",node->name,node->num,node->score);     node=node->next; }}
查看完整描述

目前暂无任何回答

  • 0 回答
  • 1 关注
  • 1148 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号