資料結構 鏈棧和順序棧的基本操作(C語言)

2021-10-21 11:55:15 字數 2039 閱讀 6876

資料結構——鏈棧和順序棧的基本操作(c語言)

對於棧,也是線性表的一種,其特點是先進**或者後進先出,就如同在手槍彈夾裡裝子彈一樣。只能在棧頂部刪除或者插入。

棧分為__鏈棧__和__順序棧__。
順序棧的基本操作:

//順序棧

//結構體型別

#define maxsize

10typedef int stackdatatype;

typedef struct stacknode stacknode;

//增--入棧

void

stackpush

(stacknode* s,stackdatatype x)

;//刪

//出棧

void

stackpop

(stacknode* s)

;//初始化

void

initstack

(stacknode* s)

;//列印

void

stackprint

(stacknode* s)

;//獲取棧頂的資料。

stackdatatype gettop

(stacknode* s)

;//銷毀棧

void

destroystack

(stacknode* s)

;//清空

void

clearstack

(stacknode*

入棧----------

// 入棧

void

stackpush

(stacknode* s, stackdatatype x)

*(s-

>top)

=x; s-

>top++

;}

出棧------------

//

void

stackpop

(stacknode* s)

*(s-

>top)=0

; s-

>top--

;}

對於棧的初始化---------------------

void

initstack

(stacknode* s)

獲取棧的資料—————

stackdatatype gettop

(stacknode* s)

}

列印

void

stackprint

(stacknode* s)

s->top=head;

//列印結束後top指向棧底,修改使其繼續指向棧頂

return

;}

獲取棧頂元素`。-——————

//取棧頂元素

stackdatatype gettop

(stacknode* s)

}

銷毀和清空棧:

//銷毀棧

void

destroystack

(stacknode* s)

//清空棧

void

clearstack

(stacknode* s)

測試介面:-------

void

test()

棧 實現鏈棧和順序棧)

按不同的儲存結構,可以將棧分為順序棧和鏈棧。順序棧的實現 typedef int datatype const int maxnum 1000 struct sqstack 判斷棧空 bool isempty else return false 判斷棧滿 bool isfull else retur...

鏈棧和順序棧的實現

順序棧 ifndef astack h define astack h include stack.h template class elem class astack public stack elem astack void clear bool push const elem item boo...

資料結構 棧 順序棧和鏈棧

順序棧 基於陣列的順序棧 include include include typedef enum status status typedef int elemtype typedef struct sqstack sqstack 函式宣告 基於陣列的順序棧 status initstack sqs...