• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

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

建立一个单链表,并使用该链表存储所有学生的信息。假设最初建立的链表名为ListA,你要将链表ListA中成成绩在1400分以上(含1400分)的节点从ListA中删去,并把这些节点插入到新链表ListB中,最后输出链表B
#include

#include
#include
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;
        }
}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031168位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!