棧和佇列的基本操作

2021-08-28 09:19:10 字數 2109 閱讀 2293

一種特殊的的線性表,只允許在固定的一端進行插入和刪除操作。棧被稱作是先進後出的線性表。

只允許在一端進行插入資料操作,在另一端刪除資料操作的特殊線性表。具有先進先出的特性。

迴圈佇列(簡單了解)

隊空 rear == front;

隊滿 (rear + 1) % maxsize == front;

初始化、銷毀、增、刪、查

typedef int stackdatatype;

#define max_size (100)

typedef struct stack stack;

void stackinit(stack* pstack)

void stackdestroy(stack* pstack)

void stackpush(stack* pstack, stackdatatype data)

void stackpop(stack* pstack)

stackdatatype stacktop(stack* pstack)

int stacksize(const stack *pstack)

int stackfull(const stack *pstack)

int stackempty(const stack *pstack)

初始化、銷毀、插入(隊尾插入)、刪除(隊頭刪除)、檢視隊首資料

}

//建立節點

static qnode * createnode(qdatatype data)

void queuepush(queue *pqueue, qdatatype data)

pqueue->rear->next = newnode;

pqueue->rear = newnode;

}

void queuepop(queue *pqueue)

}

qdatatype queuefront(queue *pqueue)

int queueempty(const queue *pqueue)

int queuesize(const queue *pqueue)

return size;

}

棧和佇列的基本操作

看歐立奇的 程式設計師面試寶典 的棧和佇列的部分,發現了部分問題。其中棧的部分,不能簡單的用malloc函式來初始化stack,應該呼叫create 函式 而且棧的base應該指向棧的最下面的資料的下乙個位址。全部除錯通過 棧的部分通過單鏈表來實現鏈棧的結構 include using namesp...

棧和佇列的基本操作

資料結構 棧和佇列的基本操作 棧的基本操作 include include define true 1 define false 0 define ok 1 define error 1 define overflow 2 define stack init size 100 define stac...

C 中棧和佇列的基本操作

使用標準庫的棧和佇列時,先包含相關的標頭檔案 include include 定義棧如下 stacks 定義佇列如下 queueq 棧提供了如下的操作 s.empty 如果棧為空返回true,否則返回false s.size 返回棧中元素的個數 s.pop 刪除棧頂元素但不返回其值 s.top 返回...