以下是代码部分,建立链表首先要声明一个结构体,并在结构体中声明一个指向本结构体的next指针。
在声明结构体的时候,内存并没有分配,是在赋值的时候使用内存。
#define NULL 0
struct student
{
long num;
float score;
struct student *next;
};
main()
{
struct student a,b,c,*head,*p;
a.num=99101;a.score=89.5;
b.num=99103;b.score=90;
c.num=99107;c.score=85;
head=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
p=head;
fun();
do
{
printf("%ld %5.1f/n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}