注意:L可以表示为头指针或是头结点,L->next可以表示为头结点的下一个结点
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
typedef int ElemType;
//定义一个链表
typedef struct LNode
{
ElemType data;//结点的数据域
struct LNode* next;//结点的指针域
}LNode, * LinkList;
bool InitList(LinkList L);//初始化链表
LNode* GetElem(LinkList L, int i);//按位查找
LNode* LocateElem(LinkList L, ElemType e);//按值查找
bool ListInsert(LinkList L, int i, ElemType e);//按位序插入
bool InsertNextNode(LNode* p, ElemType e);//指定结点的后插操作
bool InsertPriorNode(LNode* p, ElemType e);//指定结点的前插操作
bool ListDelete(LinkList L, int i, ElemType e);//按位序删除
bool DeleteNode(LNode* p);//删除指定结点
int length(LinkList L);//求链表表长
LinkList List_Taillnsert(LinkList L);//用尾插法建立单链表
bool PrintList(LinkList L);//打印链表的元素
bool InitList(LinkList L)//初始化链表
{
printf("********初始化单链表********\n");
L = (LinkList)malloc(sizeof(LNode));//生成新结点作为头结点,用头指针L指