帶頭雙向迴圈鍊錶

2021-10-02 21:44:52 字數 1465 閱讀 1015

帶頭雙向迴圈鍊錶的增刪查改實現

//帶頭+雙向+迴圈鍊錶增刪查改實現

typedef

int ltdatatype;

typedef

struct listnode

listnode;

//建立乙個新節點

listnode*

buylistnode

(ltdatatype x)

//建立返回鍊錶的頭節點

listnode*

listcreate()

//雙向鍊錶銷毀

//定義乙個指向第乙個節點的指標(第乙個節點不是頭節點)

//迴圈遍歷,依次釋放,並將指標指向下乙個要釋放的位置

//迴圈結束後,頭節點需要單獨釋放,並將頭指標置空

void

listdestory

(listnode* phead)

while

(cur != phead)

free

(phead)

; phead =

null;}

//雙向鍊錶列印

void

listprint

(listnode* phead)

printf

("\n");

}//雙向鍊錶尾插

void

listpushback

(listnode* phead, ltdatatype x)

//雙向鍊錶尾刪

void

listpopback

(listnode* phead)

//雙向煉表頭插

void

listpushfront

(listnode* phead, ltdatatype x)

//雙向煉表頭刪

void

listpopfront

(listnode* phead)

//雙向鍊錶查詢

listnode*

listfind

(listnode* phead, ltdatatype x)

cur = cur->next;

}return

null;}

//雙向鍊錶在pos位置的前面進行插入

void

listinsert

(listnode* pos, ltdatatype x)

//雙向鍊錶刪除pos位置的節點

void

listerase

(listnode* pos)

帶頭雙向迴圈鍊錶

首先,我們來看一下帶頭雙向迴圈鍊錶的結構 目錄 帶頭雙向迴圈鍊錶結點的定義 相關操作介面 1 初始化 獲取乙個結點 2 銷毀鍊錶 3 尾插 4 頭插 5 指定元素查詢 6 任意位置插入 7 尾刪 8 頭刪 9 任意位置刪除 10 列印鍊錶 附上完整 typedef int datatype type...

雙向迴圈帶頭節點鍊錶

include include struct dblnode typedef struct dblnode dblnode typedef struct dblnode dbllink void create link dbllink head 建立鍊錶 void create newnode db...

帶頭雙向迴圈鍊錶增刪操作

標頭檔案list.h存放函式宣告 ifndef list h define list h include include include typedef int ltdatatype typedef struct listnodelistnode typedef struct listlist 初始...