当前位置 博文首页 > 127.0.0.1的博客:C语言建立简单的静态链表

    127.0.0.1的博客:C语言建立简单的静态链表

    作者:[db:作者] 时间:2021-09-08 19:50

    学习次内容前需掌握结构体和指针的使用方法,此链表为最基础的静态链表。

    #include <stdio.h>
    struct Student{
    	int num;
    	float score;
    	struct Student *next;
    };
    int main()
    {
    	struct Student a, b, c, *head, *p;
    	a.num = 10101;
    	a.score = 89.5;
    	b.num = 10103;
    	b.score = 90;
    	c.num = 10107;
    	c.score = 85;
    	head = &a;
    	a.next = &b;
    	b.next = &c;
    	c.next = NULL;
    	p = head;
    	do{
    		printf("%ld %5.1f\n", p->num, p->score);
    		p=p->next;
    	}while(p!=NULL);
    }
    

    【运行结果】
    在这里插入图片描述

    cs