赞
踩
typedef struct DNode
{
int data;
struct DNode* next;//后继指针
struct DNode* prio;//前驱指针
}DNode ,*DList;
- //初始化
- p->prio->next = p->next;
- if (p->next != NULL)//判断很重要
- {
- p->next->prio = p->prio;
- }
- free(p);
- return true;
- }
-
- //返回key的前驱地址,如果不存在返回NULL;
- DNode* GetPrio(DList plist, int key)
- {
- DNode* p = Search(plist, key);
-
- return p == NULL ? NULL : p->prio;
- }
-
- //返回key的后继地址,如果不存在返回NULL;
- DNode* GetNext(DList plist, int key)
- {
- DNode* p = Search(plist, key);
-
- return p == NULL ? NULL : p->next;
- }
-
- //输出
- void Show(DList plist)
- {
- for (DNode *p = plist->next; p != NULL; p = p->next)
- {
- printf("%d ", p->data);
- }
- printf("\n");
- }
-
- //清空数据
- void Clear(DList plist)
- {
- Destroy(plist);
- }
-
- //销毁整个内存
- void Destroy(DList plist)
- {
- assert(plist != NULL);
- if (plist == NULL)
- return;
- //总是删除第一个节点
- DNode* p;
- while (plist->next != NULL)
- {
- p = plist->next;
- plist->next = p->next;
- //可以不用处理
- /*if (p->next != NULL)
- {
- p->next->prio = plist;
- }*/
- free(p);
- }
- }
双向链表其实和单链表一样,就是把两条方向的单链表都处理好就行.
双向链表的考点就是多级指针,一定要注意判断;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。