資料結構 鏈佇列 帶頭結點

2021-10-08 11:03:14 字數 1644 閱讀 5722

5.小結

#include

#include

#define elemtype int

typedef struct linknode linknode;

typedef struct linkqueue;

/*函式宣告*/

void

initqueue

(linkqueue&q)

;//1.初始化佇列

bool liqueueempty

(linkqueue q);

//2.判空

bool enqueue

(linkqueue&

q, elemtype x)

;//3.入隊操作

bool exqueue

(linkqueue&

q, elemtype& x)

;//4.出隊操作

bool gethead

(linkqueue q

, elemtype& x)

;//5.獲取隊頭元素

//1.初始化佇列(帶頭結點) 

void

initqueue

(linkqueue&q)

//2.判空(帶頭結點)

bool liqueueempty

(linkqueue q

)

//3.入隊操作(無頭結點)

//3.入隊操作(帶頭結點)

bool enqueue

(linkqueue&

q, elemtype x)

//4.出隊操作(帶頭結點)

bool exqueue

(linkqueue&

q, elemtype& x)

//5.獲取隊頭元素

bool gethead

(linkqueue q

, elemtype& x)

int main()

關於不帶頭結點和帶頭結點的區別

其實和帶頭結點與不帶頭結點的單鏈表的區別沒有大的區別。

(1)入隊無區別:對無頭結點的鏈佇列來說,入隊(插入)操作的物件如果是第乙個結點需要單獨處理,而帶頭結點的鏈佇列則不需要,因為頭指標永遠指向頭結點。

(2)出隊有區別:而在引入隊尾指標後,無論是帶頭結點還是不帶頭結點,在出隊(刪除)操作的物件是最後乙個結點時也需要單獨進行處理,修改隊尾指標。

有關佇列的應用說明

(1)在計算機系統中的應用

①緩衝區佇列

②cpu資源競爭

③頁面置換演算法中的fifo

(2)在層次遍歷中的應用

樹的層次遍歷

圖的廣度優先遍歷

關於佇列在層次遍歷中的作用,會在後續的文章中重點介紹。

資料結構 佇列 不帶頭結點

佇列 鏈式儲存結構 include include define error 1 define ok 0 typedef int elemtype typedef struct node node typedef struct linkqueue linkqueue int inqueue link...

帶頭結點的鏈佇列實現

佇列 queue 在電腦科學中,是一種先進先出的線性表。和棧相反,它只允許在表的一端進行插入,而在表的另一端刪除元素。佇列是一種特殊的線性表,它只允許在表的前端 front 進行刪除操作,而在表的後端 rear 進行插入操作。進行插入操作的端稱為隊尾,進行刪除操作的端稱為隊頭。佇列中沒有元素時,稱為...

資料結構 單鏈表 帶頭結點和不帶頭結點

1 單鏈表 通過各結點的鏈結指標來表示結點間的邏輯關係,長度可擴充,遍歷或查詢 2 只能從指標的指示的首元結點開始,跟隨鏈結指標逐個結點進行訪問,進行刪除或插 4 5 6 單鏈表的結構定義 7 typedef int datatype 8 typedef struct node 9 linknode...