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

建立和输出一个简单的链表

时间:2014-12-12 13:24:37      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:struct   c   

#include <stdio.h>
#define NULL 0
struct student
{
    long num;
    float score;
    struct student * next
};


void main()
{
    struct student a,b,c, *head, *p;
    a.num = 1001;
    a.score = 89.2;
    b.num = 1002;
    b.score = 90.1;
    c.num = 1003;
    c.score = 92.1;
    head = &a;
    a.next = &b;
    b.next = &c;
    c.next = NULL;
    p = head;


    do{
        printf("%ld %5.2f\n",p->num,p->score);
        p = p->next;
    }while ( p != NULL);

}


开始时使head指向a结点,a.next指向b节点,b.next指向c节点。这个就是关键的关系。c.next=NULL就是使c.next不指向任何存储单元。在输出链表时要借助p,先使p指向a节点,然后输出a节点中的数据。

建立和输出一个简单的链表

标签:struct   c   

原文地址:http://blog.csdn.net/u011046042/article/details/41891759

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