算法竞赛阶段二-数据结构(39)数据结构栈模拟实现
//栈模拟 实现//创建
#include <iostream>
using namespace std;
//创建
const int N=1e5+10;
int a[N],id;
//尾插
void push(int x)
{
id++;
a[id]=x;
}
//尾删 、
void pop()
{
id--;
}
// 返回栈顶元素
int top ()
{
return (a[id]);
}
//元素个数
int size()
{
return(id);
}
// 判空
bool empty()
{
return(id==0);
}
int main()
{
for(int i=0;i<5;i++)
{
push(i);
cout<<top()<<endl;
}
cout<<"________________"<<endl;
// while(!empty())
// {
// cout<<top()<<endl;
// pop();
// }
while(size())
{
cout<<top()<<endl;
pop();
}
return 0;
}