C語言資料結構 鏈佇列

2021-07-05 18:23:14 字數 1361 閱讀 5825

鏈佇列與鍊錶相似,不同的是它具有對列的運算方法,儲存結構和鍊錶相同,下面是其結構示意圖:

這裡的*q類似於鍊錶的頭節點*head;它包含兩個指向佇列節點的指標front和rear;當front和rear都為null時隊列為空;front指向佇列第乙個節點,rear指向最後乙個節點,當兩者指向同乙個節點說明佇列只有乙個節點;

還有不設頭指標的鏈佇列表示形式,這裡不予說明;

#include

#include

#define datatype int

//定義節點結構

typedef struct nodequeuenode;

//定義頭節點

typedef structlinkqueue;

//初始化鏈佇列,頭節點置空

void initqueue(linkqueue *q)

//判斷鏈佇列是否為空

int queueempty(linkqueue *q)

//入隊

void enlinkqueue(linkqueue *q, datatype v)

}//出隊

datatype delinkqueue(linkqueue *q)

//讀取佇列頭元素,不改變佇列狀態

datatype readlinkqueue(linkqueue *q)

int main()

printf("delinkqueue: %d\n", delinkqueue(&q));

printf("delinkqueue: %d\n", delinkqueue(&q));

printf("readlinkqueue: %d\n", readlinkqueue(&q));

printf("readlinkqueue: %d\n", readlinkqueue(&q));

enlinkqueue(&q,9);

printf("the all number of the linkqueue:\n");

while(!queueempty(&q))

printf("%d\t",delinkqueue(&q)); //輸出佇列中所有資料

return

0;}

測試輸出結果:

delinkqueue : 1

delinkqueue : 2

readlinkqueue : 3

readlinkqueue : 3

the all number of the linkqueue:

3 4 5 6 9

資料結構(C語言) 鏈佇列基本操作

文章首發於2020 10 15 知乎文章 資料結構 c語言 鏈佇列基本操作 佇列是一種先進先出 first in first out,fifo 的線性表,是一種常用的資料結構。它只允許在表的前端 front 進行刪除操作,而在表的後端 rear 進行插入操作,和棧一樣,佇列是一種操作受限制的線性表。...

資料結構(C實現) 鏈佇列

鏈佇列,即佇列的鏈式儲存結構,它是僅在表頭刪除和表尾插入的單鏈表,因此乙個鏈佇列需要設定兩個分別指示隊頭元素和隊尾元素的指標,為了操作方便,給鏈佇列新增乙個頭結點,並令隊頭指標指向頭結點,由此,空的鏈佇列的判斷條件就是隊頭指標和隊尾指標均指向頭結點。鏈佇列型別描述 typedef int qelem...

資料結構 鏈佇列

佇列沒完全看懂 include include define datatype int 定義節點結構 typedef struct nodequeuenode 定義頭節點 typedef structlinkqueue 初始化鏈佇列,頭節點置空 void initqueue linkqueue q ...