- 单链表
也就是线性表的链式存储,它是指通过一组任意的存储单元来存储线性表中的数据元素,每个链表结点包含存放数据元素的数据域(data域)和存放后继结点的指针域
单结点的结点类型描述
typedef struct LNode
{
Elemtype data;
struct LNode *next;
}LNode,*Linklist;
//或
typedef struct LNode
{
int data;
struct LNode *next;
}LNode;
利用单链表可以解决顺序表需要大量连续存储空间的特点,但是单链表附加了指针域,也存在浪费存储空间的缺点。因为单链表的元素是离散地分布在存储空间中,所以单链表是非随机存储的存储结构
双链表结点定义
typedef struct DLNode
{
int data;
struct DLNode *prior;
struct DLNode *next;
}DLNode;
//另一种定义方式如上类推
单链表基本操作
- 头插法
LinkList List_headInsert(Linklist &L)
{
LNode *s;
int x;
L=(Linklist)malloc(sizeof(LNode));//malloc函数创建头结点
L->next=NULL;//初始为空链表
scanf("%d",&x);
while(x!=500)
{
s=(LNode*)malloc(sizeof(LNode));
s->data=x;
s->next=L