c语言:链表

1.链表概述:

链表是一种数据结构,它采用动态分配存储单元方式。它能够有效地节省存储空间(同数组比较)。

由于链表中的节点是一个结构体类型,并且结点中有一个成员用于指向下一个结点。所以定义作为结点的格式:

struct 结构体名{

定义结构体成员;

struct 结构体名 *指针变量名;

}

如:

struct student { 

  int num;

  float score;

  struct student *next;

};

struct student a,*p;

2.动态存储分配函数<stdlib.h>

(1)malloc()函数

作用是在内存的动态存储区中分配一个长度为size个字节的连续空间,函数返回值是一个指向分配域起始地址的指针若分配失败则返回NULL。

如:

struct student *p=(struct student*)malloc(sizeof(struct student));

(2.)free()函数

作用是释放用malloc()分配的内存

猜你喜欢

转载自www.cnblogs.com/SanChauncy/p/9500647.html