例1:输出一个链表及其中记录的条数。
void print(struct student *head)
{
struct student *p=head;
int n=0;
while(p!=NULL)
{
n++;
printf("%ld\t%d\n",p->num,p->score);
p=p->next;
}
printf("There are %d records.",n);
}
例2:链表的使用
#include<stdio.h>
#include<malloc.h>
struct student
{
long num;
int score;
struct student *next;
};
struct student *creat(void)
{
…… ……
}
void print(struct student *head)
{
…… ……
}
main()
{
struct student *head;
head=creat();
print(head);
}