小白菜*** 2022-01-06 18:46 采纳率: 100%
浏览 35
已结题

学生链表的构造与输出

问题遇到的现象和发生背景

学生链表的构造与输出

问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
#include  <iostream>
#include  <iomanip>
using  namespace  std;

struct  Student{
        long  number;
        float  score;
        Student*  next;
};

;  //  定义头节点

Student*  getNode(){
        int  num;
        float  sc;
        cin  >>  num  >>  sc;
        if(num  ==  0)  {
                return  NULL;
        }
        Student*  p  =  new  Student;
        p->number  =  num;
        p->score  =  sc;
        p->next  =  0;
        return  p;
}

void  Create()  {
        if((head  =  getNode())  ==  0)  {    //  添加结束条件
                
break;
;
        }
        for  (       )  {    //  循环添加
                pE->next  =  pS;
        }
}

void  ShowList()  {
        cout  <<  "now  the  itens  of  list  are  \n";
        for(         )  {    //  循环输出
                cout<<  p->number  <<  ","  <<  p->score  <<  endl;
        }
}

int  main(){
        cout  <<  fixed  <<  setprecision(1);
        Create();
        ShowList();
}

  • 写回答

1条回答 默认 最新

  • _GX_ 2022-01-06 19:06
    关注
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    struct Student
    {
        long number;
        float score;
        Student *next;
    };
    
    Student *head; //  定义头节点
    
    Student *getNode()
    {
        int num;
        float sc;
        cin >> num >> sc;
        if (num == 0)
        {
            return NULL;
        }
        Student *p = new Student;
        p->number = num;
        p->score = sc;
        p->next = 0;
        return p;
    }
    
    void Create()
    {
        if ((head = getNode()) == 0)
        { //  添加结束条件
            return;
        }
    
        for (Student *pE = head, *pS = getNode(); pS; pE = pS, pS = getNode())
        { //  循环添加
            pE->next = pS;
        }
    }
    
    void ShowList()
    {
        cout << "now  the  itens  of  list  are  \n";
        for (Student *p = head; p; p = p->next)
        { //  循环输出
            cout << p->number << "," << p->score << endl;
        }
    }
    
    int main()
    {
        cout << fixed << setprecision(1);
        Create();
        ShowList();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 1月16日
  • 已采纳回答 1月8日
  • 创建了问题 1月6日

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题