#include<iostream>
typedef int Elemtype;
const int MaxSize = 50; //设置链表最大长度
/*
1.栈顶Top值不能超过MaxSize
2.空栈的判定条件通常定为top == -1,满栈的判定条件通常为top == MaxSize-1
栈中元素个数为top+1
*/
//顺序栈
typedef struct {
Elemtype data[MaxSize]; //栈中存放元素的个数
int top = -1;
}SqStack;
//判空
bool StackEmpty(SqStack s) {
if (s.top == -1)
return true;
else
return false;
}
//进栈
bool Push(SqStack &s, Elemtype e) {
if (s.top == MaxSize - 1) //栈满
return false;
s.data[++s.top] = e; //先加再进
return true;
}
//出栈
bool Pop(SqStack &s, Elemtype &e) {
if (s.top == -1)
return false;
e = s.data[s.top--]; //先出再减
return true;
}
//读取栈顶元素
bool getTop(SqStack s, Elemtype &e) {
if (s.top == -1)
return false;
e = s.data[s.top]; //直接用无需修改
return true;
}
int main() {
}