双向链表
以前手把手的时候写过,硬盘里还保存有代码, 以前写的时候还去看了glib的实现,要不要作弊? 呵呵、、当然不要,这次完全按照自己的理解来。
- typedef struct _List List;
- struct _List;
- {
- void* data;
- List* prev;
- List* next;
- };
- List* list_new (void)
- {
- List* thiz = NULL;
- thiz = (List*) malloc (sizeof(List));
- return thiz;
- }
- void list_free (List* thiz)
- {
- if (thiz)
- free (thiz);
- }
- List* list_last (List* thiz)
- {
- if (!thiz) return NULL;
-
- List* node = thiz;
- while (node->next)
- node = node -> next;
- return node;
- }
- List* list_append (List* thiz, void* data)
- {
- List* node = list_new ();
- node -> data = data;
- return thiz;
- }
这个网吧真不习惯、、、中午休息写。
本文介绍了一种双向链表的数据结构实现方法,包括链表节点定义、创建新链表及追加元素等基本操作。
1万+

被折叠的 条评论
为什么被折叠?



