码迷,mamicode.com
首页 > 其他好文 > 详细

第13周 补充阅读-链表类1

时间:2017-05-12 13:17:25      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:enter   struct   net   clu   include   content   动态   sso   log   

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


执行结果:

技术分享

 

 

第13周 补充阅读-链表类1

标签:enter   struct   net   clu   include   content   动态   sso   log   

原文地址:http://www.cnblogs.com/ljbguanli/p/6844848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!