# 说在前面

typedef struct node {
int data;
struct node * next;
}node, list_node;


node node_1;
node node_2;
node node_3;


node_1->next = node_2;
node_2->next = node_3;
node_3->next = NULL;


typedef struct lively_node {
int data;
string str;
char ch;
my_type my_data;
node my_node;
}lively_node, smart_node;


typedef struct node {
int data;
struct node * forward;
struct node * next;
}node, list_node;


node node_1;
node node_2;
node node_3;


node_1->next = node_2;
node_2->next = node_3;
node_3->next = NULL;


node_3->forward = node_2;
node_2->forward = node_1;


# 链表操作

0、链表之前
1、创建结点
2、头插法
3、尾插法
4、按索引插入
5、按索引获取结点
6、打印链表
7、删除结点
8、清空链表
9、销毁链表

## 0、链表之前

typedef struct list {
int data;
struct list * forward;
struct list * next;


## 1、创建结点

list * create(int value) {
list * node = NULL;

node = (list *)malloc(sizeof(list));
if (node == NULL) {
return NULL;
}
node->data = value;
node->forward = NULL;
node->next = NULL;

return node;
}


## 2、头插法

int head_insert_list(list * link, int value) {
if (link == NULL) return -1;
list * node = NULL;

node = (list *)malloc(sizeof(list));
if (node == NULL) return -2;
node->data = value;

return 0;
}


## 3、尾插法

int tail_insert_list(list * link, int value) {
if (link == NULL) return -1;
list * node = NULL;

node = (list *)malloc(sizeof(list));
if (node == NULL) return -2;
node->data = value;
}
node->next = NULL;

return 0;
}


OK，一起正常，接下来实现按索引插入结点。

## 4、按索引插入

int index_insert_list(list * link, int index, int value) {
if (link == NULL) return -1;
list * node = NULL;

node = (list *)malloc(sizeof(list));
if (node == NULL) return -2;
if (index == 0) {
return 0;
}
node->data = value;
while (index - 1 && link->next) {
index--;
}
if (index - 1 != 0) return -3;
else if (link->next == NULL) {
return 0;
}
else {
node->next->forward = node;
}

return 0;
}


## 5、按索引获取结点

int index_print_list(list * link, int index) {
if (link == NULL) return -1;
index--;
}
if (index != 0) return -3;

return 0;
}


## 6、打印链表

int print_list(list * link) {
if (link == NULL) return -1;
}
printf("\n");

return 0;
}


## 7、删除结点

int index_delete_list(list * link, int index) {
if (link == NULL) return -1;
list * node = NULL;

if (index == 0) {
free(node);
node->forward = NULL;
node->next = NULL;
node = NULL;

return 0;
}

index--;
}
if (index != 0) return -3;
else if (link->next == NULL) {
node->forward->next = NULL;
free(node);
node->forward = NULL;
node->next = NULL;
node = NULL;

return 0;
}
else {
node->forward->next = node->next;
node->next->forward = node->forward;
free(node);
node->forward = NULL;
node->next = NULL;
node = NULL;

return 0;
}
}


## 8、清空链表

int clean_list(list * link) {
if (link == NULL) return -1;
}

return 0;
}


## 9、销毁链表

int destroy_list(list * link) {
if (link == NULL) return -1;
list * node = NULL;

}

return 0;
}


OK，一切大功告成，请读者批评指正！

11-25 3万+

07-29 96
03-29 541
03-29 1616
03-04 5279
09-05 264
01-13 29
05-10 342
06-06 9355
04-23 1887
08-24 46
04-17 9831
03-02 38
03-28 1004