栈
特点:先进后出,后进先出
栈的运算
(1)初始化:设置栈为空
(2)判断栈是否空:若空return ture,否则return false
(3)判断栈是否满:若满return ture,否则return false
(4)取栈顶元素:
条件:栈不为空
(5)入栈:将元素放到栈顶
(6)出栈:删除当前栈顶的元素
顺序栈
stack类的完整描述
封装类:
class stack{
public:
stack();
~stack();
bool isempty()const;
bool isfull()const;
error_code get_top(elemenType &x) const;
error_code push(const elemenType x);
error_code pop();
private:
int count;
elemenType data[maxlength];}
初始化运算
stack::stack(){
count=0;}
判断为空
bool stack::isempty() const{
if(count0)return ture;
else return false;}
判断为满
bool stack::isfull()const{
if(countmaxlength)return ture;
else return false;
取栈顶元素
error_code stack::get_top(elemenType &x){
if(isempty())return underflow;
else{
x=data[count-1];}
return success;
入栈
error_code stack::push(const elemenType x){
if(isfull())return overflow;
else{
data[count]=x;
count++;
return success;}
出栈
error_code stack::pop(){
if(isempty()) return underflow;
count–;
return success;
双头栈
答案选B
栈的应用-表达式的计算![在这里插入图片描述](https://img-blog.csdnimg.cn/20210404100737746.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81MjkyNDM1OA==,size_16,color_FFFFFF,t_70#pic_center)