#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();
}
学生链表的创建与输出
最新推荐文章于 2023-06-15 08:52:54 发布
该博客介绍了如何使用C++创建一个学生信息链表,包括输入学生编号和分数,通过`getNode()`函数动态添加节点,并利用`Create()`函数构建链表。最后,`ShowList()`函数遍历链表并打印所有学生信息。
摘要由CSDN通过智能技术生成