链表是一种常用的数据结构,每个节点通过链或者指针链接在一起,程序通过间接指针访问链表中的节点。
typedef struct Node {
//指向下一个节点的指针
struct Node *next;
int value;
}
单链表只可以单向遍历
单链表中插入:第一版
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
typedef struct Node {
struct Node *next;
int value;
} LinkList;
//假设链表从小到大排序
int linkInsert(LinkList * current, int value)
{
//保存前一个节点
LinkList *previous;
LinkList *new;
//循环到合适的位置
while (current-> value < value) {
previous = current;
current = current->next;
}
new = malloc(sizeof(LinkList));
if (new == NULL) {
return FALSE;
}
new->value = value;
new->next = current;
previous->next = new;
return TRUE;
}
原文:http://www.cnblogs.com/yangxunwu1992/p/5844132.html