学生链表的构造与输出
#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();
}
#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();
}