第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;
}


执行结果:

 

 

posted on 2017-05-12 11:50  ljbguanli  阅读(85)  评论(0编辑  收藏  举报