#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节点中的数据。
时间: 2024-10-06 01:26:32