#include<iostream>
using namespace std;
//设置数组的最大值
#define MaxSize 100
int A[MaxSize];
//栈顶
int top=-1;
//入栈
void push(int x){
//处理溢出的情况
if(top==MaxSize-1){
cout<<"stack overflow"<<endl;
return;
}
top++;
A[top]=x;
}
//弹出
void pop(){
if(top==-1){
cout<<"no element to pop"<<endl;
return;
}
top--;
}
//输出栈的内容
void output(){
if(top!=-1){
cout<<"the list is:";
for(int i=0;i<=top;i++){
cout<<A[i];
cout<<" ";
}
}
}
int main(){
push(10);
push(2);
push(5);
output();
pop();
output();
}
标签:cout,int,top,c++,MaxSize,数组,push,数据结构,void From: https://blog.csdn.net/dashuchengtian/article/details/141717534