什么是链表,这种数据结构是由一组Node组成的,这群Node一起表示了一个序列。链表是最普通,最简单的数据结构,它是实现其他数据结构如stack, queue等的基础。
链表比起数组来,更易于插入,删除。
Node可以定义如下:
typedef int element_type;
typedef struct node *node_ptr;
struct node {
element_type element;
node_ptr next;
};
接下来重点实现单链表的反转,这也是常常考到的一个问题,下面是C语言实现:
void list_reverse(LIST L)
{
if (L->next == NULL) return;
node_ptr p = L->next, first = L->next;
while (p != NULL && p->next != NULL) {
node_ptr next_node = p->next;
p->next = next_node->next;
next_node->next = first;
first = next_node;
}
L->next = first;
}
https://github.com/booirror/data-structures-and-algorithm-in-c
原文:http://blog.csdn.net/booirror/article/details/45373531