
#include
#include
#define MaxSize 20
typedef struct {
int data[MaxSize];//数组
int top;//栈顶
}SqStack;//顺序栈存储类型
void InitStack(SqStack s) {
s.top = -1;
}//初始化
bool StackEmpty(SqStack s) {
if (s.top != 1) {
return false;
}
else
return true;
}//判空
bool push(SqStack s, int x) {
if (s.top == MaxSize - 1) {
return false;//栈已满
}
else {
s.data[s.top + 1] = x;
s.top = s.top + 1;
//s.data[++s.top]=x;
}
return true;
}//进栈
bool pop(SqStack s, int x) {
if (s.top == -1) {
return false;
}
else
s.data[s.top--] = x;
return true;
}//出栈
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)