1、头文件(.h)
#ifndef __LINKLIST_H__
#define __LINKLIST_H__
#define FALSE 0
#define TRUE 1
typedef int LinkData;
typedef struct _node
{
LinkData data;
struct _node * next;
}Node;
// 创建链表
Node * Create_List();
// 尾插
int Insert_Last(Node *h, LinkData data);
// 头插
int Insert_Head(Node *h, LinkData data);
// 在第 pos 个结点处插入数据
int Insert_Pos(Node *h, int pos, LinkData data);
void Display(Node *h);
#endif
2、三种插入函数
//头插
int Insert_Head(Node *h, LinkData data)
{
if (h == NULL)
return FALSE;
Node *node = (Node*)malloc(sizeof(Node)/sizeof(char));
if (node == NULL)
{
return FALSE;
}
node->data = data;
node->next = h->next;
h->next = node;
return TRUE;
}
//尾插
int Insert_Last(Node *h, LinkData data)
{
if (h == NULL)
return FALSE;
Node *node = (Node*)malloc(sizeof(Node)/sizeof(ch