棧與佇列 判斷棧 隊列為空 滿

2021-07-14 03:03:35 字數 1480 閱讀 9563

陣列棧

完成int isempty(stack s)函式,該函式判斷棧是否已空,如果空返回1,否則返回0。

完成int isfull(stack s)函式,該函式判斷棧是否已滿,如果滿返回1,否則返回0。

typedef

int elemtype;

struct stackrecord;

typedef

struct stackrecord *stack;

struct stackrecord

;int isempty(stack s)

else

}int isfull(stack s)

else

}

鏈棧

完成int isempty(stack s);函式,該函式判斷棧s是否為空,空棧返回1,否則返回0,已知s是帶頭結點的鏈棧。

typedef

int elemtype;

struct node;

typedef

struct node * ptrtonode;

typedef ptrtonode stack;

struct node

;int isempty(stack s)

陣列佇列

完成int isempty(queue q);函式,該函式判斷佇列q是否已空,如果已空返回1,否則返回0,其中q是基於陣列的非迴圈佇列。

完成int isfull(queue q)函式,該函式判斷佇列q是否已滿,如果已滿返回1,否則返回0,其中q是基於陣列的非迴圈佇列。

typedef

int elemtype;

struct queuerecord;

typedef

struct queuerecord * queue;

struct queuerecord

;int isempty(queue q)

int isfull(queue q)

鏈佇列

完成int isempty(queue q)函式,該函式判定基於鍊錶的佇列q是否為空,空佇列返回1,非空佇列返回0,其中q是不帶頭節點的鍊錶佇列。

typedef

int elemtype;

struct node;

typedef

struct node node;

struct

queue;

typedef

struct

queue * queue;

struct node

;struct

queue

;int isempty(queue q)

迴圈佇列判斷滿與空

何時隊列為空?何時為滿?由於入隊時尾指標向前追趕頭指標,出隊時頭指標向前追趕尾指標,故隊空和隊滿時頭尾指標均相等。因此,我們無法通過front rear 來判斷佇列 空 還是 滿 注 先進入的為 頭 後進入的為 尾 解決此問題的方法至少有三種 其一是另設乙個布林變數以匹別佇列的空和滿 其二是少用乙個...

判斷棧是否為空 棧與佇列簡介

棧與佇列和陣列 鍊錶 樹這幾種資料結構不太一樣。棧與佇列主要是做為程式設計師的工具來使用,它們主要做為構思演算法的輔助工具,而不是完全的資料儲存工具。它們的生命週期比陣列那些要短得多,在程式執行期間它們才會被建立,任務執行完就會被銷毀。棧是一種只能在一端進行插入和刪除資料的資料結構,這一端被稱為棧頂...

棧與佇列 建立棧 佇列

陣列棧 完成stack createstack int maxelements 函式,該函式建立乙個棧,maxelements為與分配的棧空間大小 棧可用空間為array 0,maxelements 1 typedef int elemtype struct stackrecord typedef ...