佇列的順序 鏈式儲存實現

2022-05-03 02:12:08 字數 1117 閱讀 7488

佇列:具有一定操作約束的線性表,只能在一端插入,在另一端刪除。

特點:先來先服務,先進先出表

頭front,尾rear

順序儲存

1

#define maxsize 《儲存資料元素的最大個數》23

struct

qnode ;

1213 typedef struct qnode *queue;

14  //front = rear = -1;

迴圈佇列的儲存辦法:

(1)使用額外標記:size或者tag(插入為1,刪除為0) 域

(2)僅使用n-1個陣列空間

(1)入佇列(迴圈佇列)

1

void

addq (queue ptrq, elementtype item)

10   //這兩句看情況進行交換

11   ptrq->reat = (ptrq->rear+1) %maxsize;

1213   ptrq->data[ptrq->rear] =item;

1415 }

(2)出佇列

elementtype deleteq ( queue ptrq )

else

}

鏈式儲存

structnode ;

struct qnode ;

typedef struct qnode *queue;

queue ptrq;

插入和刪除操作分別在鍊錶的兩頭進行

不帶頭結點的鏈式佇列出隊操作

elementtype deleteq ( queue ptrq )

frontcell = ptrq->front;

if (ptrq->front == ptrq->rear)  //若佇列只有乙個元素

ptrq->front = ptrq->rear = null;  //刪除後置隊列為空

else

frontelem = frontcell->data;

free(frontcell);

returnfrontelem;

}

佇列的鏈式儲存實現

include include define true 1 define false 0 define ok 1 define error 0 define overflow 02 typedef int qelemtype typedef int status storage structure ...

鏈式儲存的佇列的實現

2013 08 18 20 07 25 鏈式儲存的佇列的實現,包括佇列的初始化 銷毀 入隊 出隊 測長 獲取隊首元素等基本操作。注意幾點 佇列結構,包含乙個頭指標 乙個尾指標,初始化為空佇列,空佇列的隊首指標與隊尾指標相同 鍊錶包含頭結點,否則在隊列為空以及佇列只有乙個元素時都是隊尾至真與隊首指標相...

鏈式棧 鏈式佇列 順序佇列

暑期學習第一天,學習了鏈式棧 鏈式佇列和順序佇列 這三種都是舉一反三的型別 鏈式棧標頭檔案 ifndef stack h define stack h define ok 0 define error 1 結點 typedef struct stacknode stacknode 棧 typedef...