C 语言实例4——建立简单的静态链表

为了建立链表 使head指向a节点,a.next指向b节点,b.next指向c节点这就构成了链表关系。

#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);
	 return 0;
}

运行结果:

C 语言实例4——建立简单的静态链表