学生链表的创建与输出

该博客介绍了如何使用C++创建一个学生信息链表,包括输入学生编号和分数,通过`getNode()`函数动态添加节点,并利用`Create()`函数构建链表。最后,`ShowList()`函数遍历链表并打印所有学生信息。
摘要由CSDN通过智能技术生成

#include  <iostream>
#include  <iomanip>
using  namespace  std;
struct  Student{
        long  number;
        float  score;
        Student*  next=NULL;
};
Student *head=new Student;
 
Student *pE=head;
Student *p=head;
Student *p1=head,*p2; 

 

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*pS=getNode() ,*p11=head; pS !=NULL; pE=pS,pS=getNode(),p=head)  { 
	           //cout<<"begincreating"<<endl;
		 cout<<  p->number  <<  ","  <<  p->score  <<  endl;
                pE->next  =  pS;
         
}
}
void  ShowList()  {
        cout  <<  "now  the  itens  of  list  are  \n";
        for(p->next=p1->next;p !=NULL;p=p->next )  {    //  循环输出
                cout<<  p->number  <<  ","  <<  p->score  <<  endl;
        }
}
int  main(){
        cout  <<  fixed  <<  setprecision(1);
        Create();
        ShowList();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值