首页 > 其他 > 详细

建立简单的静态链表

时间:2020-02-08 18:34:11      阅读:79      评论:0      收藏:0      [点我收藏+]
 1 #include <stdio.h>
 2 struct student
 3 {
 4     int num;
 5     float score;
 6     struct student*next;
 7  };
 8 int main()
 9 {
10    struct student a,b,c,*head,*p;
11    a.num=10101;a.score=89.5;
12    b.num=10103;b.score=90; 
13    c.num=10103;c.score=90; 
14    head=&a;
15    a.next=&b;
16    b.next=&c;
17    c.next=NULL;
18    p=head;
19    do{
20        printf("%ld%5.1f\n",p->num,p->score);
21        p=p->next;
22    }while(p!=NULL);
23     return 0;
24 }

head指向a的结点,a.next指向b的结点·······c.next=null是为了不让其指向任何存储单元

需要定义一个指针变量来接受head的地址

本程序所有节点都是在程序中定义的所以用完后不能释放,为静态链表

建立简单的静态链表

原文:https://www.cnblogs.com/ZJK132/p/12283764.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!