資料結構 線性表 順序棧的操作

2021-09-25 01:30:32 字數 1029 閱讀 2010

**如下:

#include #include #define maxsize 50

// 使用陣列實現棧的結構;

typedef int elemtype;

typedef struct stacksqstack;

/*初始化棧

void initstack(sqstack &s);

判斷棧空

bool stackempty(sqstack s);

判斷棧滿

bool stackoverflow(sqstack s);

進棧bool push(sqstack &s,elemtype x);

出棧bool pop(sqstack &s,elemtype &x);

獲取棧頂的元素

bool gettop(sqstack s,elemtype &x);

銷毀棧直接另棧頂top指標直接-1; 比較粗暴不寫了;

*/void initstack(sqstack &s)

bool stackempty(sqstack s)

bool stackoverflow(sqstack s)

bool push(sqstack &s,elemtype x)

bool pop(sqstack &s,elemtype &x)

bool gettop(sqstack s,elemtype &x)

int main()

push(s,3);

push(s,4);

push(s,5);

// 注在方法中引數引用可以在呼叫時,直接傳變數

flag=gettop(s,m);

if(flag)

flag=pop(s,m);

if(flag)

return 0;}/*

輸出是stack is empty

the top of stack element is 5

quit stack element is 5

*/

資料結構 順序線性表

順序線性表標頭檔案 ifndef vzhangseqlist define vzhangseqlisttypedef void seqlist typedef void seqlistnode 建立線性表 declspec dllexport 如果在動態庫中定義標頭檔案 這句話不可以缺少 不然會報錯...

資料結構 動態線性表操作(順序表)

define list init size 10 線性表儲存空間的初始分配量 define listincrement 5 線性表儲存空間的分配增量 動態線性表 typedef structsqlist 初始化l為空表 int initlist sqlist l 順序線性表l,空間釋放,數值置0 i...

資料結構 線性表 順序表

豐富了前邊的功能,更加完善。include include define list init size 100 線性表儲存空間的初始分配量 define listincrement 10 線性表儲存空間的分配增量 using namespace std const int overflow 2 ty...