雙鏈表介面的簡單實現

2021-10-02 15:48:34 字數 1919 閱讀 9484

雙向鍊錶相當於單鏈表來說,實現的幾個介面無疑是比較簡單的,在這一篇部落格中,我將會整理一下關於雙向鍊錶的幾個介面實現的過程,希望各位大佬多多指正。

1.首先建立乙個帶有雙向鍊錶的節點

**如下

typedef

int ltdatatype;

typedef

struct listnode

listnode;

在這個節點中,會有兩個指標用來指向鍊錶的前乙個和後乙個節點。

接下來,說明雙向鍊錶應該具有的功能

// 建立返回鍊錶的頭結點.

listnode*

listcreate()

;// 雙向鍊錶銷毀

void

listdestory

(listnode* phead)

;// 雙向鍊錶列印

void

listprint

(listnode* phead)

;// 雙向鍊錶尾插

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)

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

void

listinsert

(listnode* pos, ltdatatype x)

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

void

listerase

(listnode* pos)

;

這幾個介面的具體實現:

listnode*

buylistnode

(ltdatatype x)

//這個是先申請建立乙個節點

listnode*

listcreate()

void

listprint

(listnode* phead)

printf

("\n");

}void

listdestroy

(listnode* phead)

free

(phead);}

void

listpushback

(listnode* phead, ltdatatype x)

void

listpushfront

(listnode* phead, ltdatatype x)

void

listpopback

(listnode* phead)

void

listpopfront

(listnode* phead)

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

void

listinsert

(listnode* pos, ltdatatype x)

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

void

listerase

(listnode* pos)

以上就是雙向鍊錶一些簡單功能的實現,希望能對大家帶來幫助。這幾個介面仔細研究一下就可以搞明白的。

資料結構 雙鏈表介面的實現

結構最複雜,一般用在單獨儲存資料。實際中使用的鍊錶資料結構,都是帶頭雙向迴圈鍊錶。另外這個結構雖然結構複雜,但是使用 實現以後會發現結構會帶來很多優勢.pragma once include include include include typedef int ltdatatype typedef...

雙鏈表的簡單實現

include include include typedef int elemtype using namespace std typedef struct dulnode dulnode,dulinklist 建立帶有頭結點的雙鏈表,順序輸入 void createdulist dl dulin...

雙鏈表實現

一 實驗目的 鞏固線性表的資料結構的儲存方法和相關操作,學會針對具體應用,使用線性表的相關知識來解決具體問題。二 實驗內容 建立乙個由n個學生成績的順序表,n的大小由自己確定,每乙個學生的成績資訊由自己確定,實現資料的對錶進行插入 刪除 查詢等操作。分別輸出結果。三 源 includeconst i...