第13周 补充阅读-链表类1
#include <iostream>
using namespace std;
struct Student
{
int num;
double score;
struct Student *next;
};
int main( )
{
Student *head=NULL,*p,*q;
//建立动态链表
for(int i=0; i<3; i++)
{
p = new Student;
cin>>p->num>>p->score;
p->next=NULL;
if (i==0) head=p;
else q->next=p;
q=p;
}
//输出动态链表
p=head;
while(p!=NULL)
{
cout<<p->num<<" "<<p->score<<endl;
p=p->next;
}
return 0;
}
执行结果:
浙公网安备 33010602011771号