1. 程式人生 > >C 語言例項4——建立簡單的靜態連結串列

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;
}

執行結果: