//帶頭雙向鍊錶
#include #include #include typedef int datatype;
typedef struct listnodelistnode;
typedef struct twolisttwolist;
//初始化
void twolistinit(twolist* pt);
//銷毀
void twolistdestroy(twolist* pt);
//尾插
void twolistpushback(twolist* pt, datatype x);
//頭插
void twolistpushfront(twolist* pt, datatype x);
//尾刪
void twolistpopback(twolist* pt);
//頭刪
void twolistpopfront(twolist* pt);
//查詢
listnode* twolistfind(twolist* pt, datatype x);
//在pos 前面插入
void twolistinsert(listnode* pos, datatype x);
//刪除pos位置的元素
void twolisterase(listnode* pos);
//刪除x
void twolistremove(twolist* pt, datatype x);
void printf(twolist* pt);
#include "twolist.h"
//初始化
void twolistinit(twolist* pt)
//銷毀
void twolistdestroy(twolist* pt)
free(head);
pt->head = null;
}//尾插
void twolistpushback(twolist* pt, datatype x)
//頭插
void twolistpushfront(twolist* pt, datatype x)
//尾刪
void twolistpopback(twolist* pt)
listnode* cur = pt->head->prev;
listnode* prev = cur->prev;
free(cur);
prev->next = pt->head;
pt->head->prev = prev;
}//頭刪
void twolistpopfront(twolist* pt)
//查詢
listnode* twolistfind(twolist* pt, datatype x)
cur = pt->head->next;
next = cur->next;
while (cur != pt->head)
cur = next;
next = next->next;
} return null;
}//在pos 前面插入
void twolistinsert(listnode* pos, datatype x)
//刪除pos位置的元素
void twolisterase(listnode* pos)
//刪除x
void twolistremove(twolist* pt, datatype x)
prev = cur;
cur = next;
next = next->next; }}
void printf(twolist* pt)
}
雙向帶頭鍊錶的實現
pragma once typedef int dldatatype typedef struct dlistnode dlistnode,dnode void dlistinit dnode head 尾插 void dlistnodepushback dnode head,dldatatype ...
帶頭雙向鍊錶
ifndef list h define list h include stdio.h include assert.h include malloc.h include string.h typedef int datatype typedef struct listnode list,plist...
帶頭雙向迴圈鍊錶
首先,我們來看一下帶頭雙向迴圈鍊錶的結構 目錄 帶頭雙向迴圈鍊錶結點的定義 相關操作介面 1 初始化 獲取乙個結點 2 銷毀鍊錶 3 尾插 4 頭插 5 指定元素查詢 6 任意位置插入 7 尾刪 8 頭刪 9 任意位置刪除 10 列印鍊錶 附上完整 typedef int datatype type...