生活随笔
收集整理的這篇文章主要介紹了
顺序栈的操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
棧的定義
#include <iostream>
#define MAXSIZE 1000using namespace std
;
typedef struct
{int data
[MAXSIZE
]; int top
;
}SqStack
;
棧的操作
初始化
bool initStack(SqStack
&st
)
{st
.top
= -1;return true;
}
判斷為空
bool isEmpty(SqStack st
)
{if(st
.top
== -1)return true;elsereturn false;
}
入棧
bool pushStack(SqStack
&st
, int e
)
{if(st
.top
== MAXSIZE
- 1)return false; st
.top
++;st
.data
[st
.top
] = e
;return true;
}
出棧
bool popStack(SqStack
&st
, int &e
)
{if(st
.top
== -1)return false; e
= st
.data
[st
.top
];st
.top
--;return true;
}
獲取棧頂元素
bool getStackTopElem(SqStack st
, int &e
)
{if(st
.top
== -1)return false; e
= st
.data
[st
.top
];return true;
}
總結
以上是生活随笔為你收集整理的顺序栈的操作的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。