链表在C语言中很重要,本文所设计的链表,以一个经典的存储学生学号和成绩的结构体作为例子,具
体的结构体如下:
struct student
{
int num;
float socre;
struct student *next;
};
首先建立一个链表,具体函数如下:
#define <malloc.h> //使用malloc函数需要包含的头文件
#define NULL 0
#define LEN sizeof(struct student)
typedef struct student stu
struct student
{
long num;
float socre;
struct student *next;
}; //
注意不要忘记定义结构体大括号最后要有一个“;”
int n; //n为全局变量,本文件模块中其他函数均可使用它
stu *creat(void)
{
stu *head;
stu *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld,%ld",&p1->num,&p1->socre);
head=NULL;