问题及代码:
#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;
}
运行结果:
学习总结:练习一下感觉好像又知道了点,还好没有全忘了~~