第七十签解签:如何用C++实现出栈和入栈

来源:百度文库 编辑:中科新闻网 时间:2024/05/12 16:03:29

#include<iostream.h>
class STACK{
private:
int base[100];
public:
int size;
STACK(){size=0;};
void push(int a)//入栈
{
base[size++]=a;
}
int pop()//出栈
{
return base[--size];
}
};
int main()
{
STACK s;
s.push(3);
s.push(4);
cout<<s.pop()<<endl;
cout<<s.pop()<<endl;
system("pause");
}