線性棧的基礎操作

2021-09-30 01:38:02 字數 1513 閱讀 4207

/*

環境:dev c++ tdm-gcc 4.9.2 64-bit profiling

- 輸出大小: 1.85850429534912 mib

線性棧操作

包括線性棧的類定義(使用模板)

棧的構造與析構

棧的壓棧與彈棧

訪問棧頂元素

判斷棧空與棧滿

棧的清空

*/

template

<

class

t>

class

astack

;

template

<

class

t>

astack

::astack

(int maxstacksize)

template

<

class

t>

astack::~

astack()

template

<

class

t>

bool astack

::pop

(t &item)

item = stackarray[top]

; top--

;return

true;}

template

<

class

t>

bool astack

::push

(const t &item)

top++

; stackarray[top]

= item;

return

true;}

template

<

class

t>

bool astack

::peek

(t& item)

item = stackarray[top]

;return

true;}

template

<

class

t>

bool astack

::isfull()

template

<

class

t>

bool astack

::isempty()

template

<

class

t>

void astack

::clear()

int

main

(int argc,

char

**ar**)

case1:

case2:

case3:

case4:

case5:

default:}

}return0;

}

線性棧操作

棧是一種非常重要的資料結構,本文介紹了一些簡單的棧的操作。include typedef struct stack node stack t 初始化stack stack t init stack int index stack pdata int malloc sizeof int index i...

棧的基礎操作

棧的定義 define maxsize 100 typedef struct node seastack,pseastack 判斷棧是否為空如果為空,函式返回1 否則,返回0 int isempty pseqstack q 返回棧中被占用空間長度 int length pseqstack q 資料入...

棧基礎操作

define maxsize 50 typedef struct sqstackvoid initstack sqstack s bool stackempty sqstack s bool push sqstack s,elemtype x bool pop sqstack s,elemtype ...