自己实现的简单的Stack,没有查空满,用于算法考试
#include<iostream>
using namespace std;
const int MAX = 100;
struct MyStack
{
int data[MAX];
int top;
}stack={{0},0};
int main()
{
for(int i = 0;i<10;i++)
{
stack.data[stack.top++]=i;
if(i%2==0)
{
cout<<stack.data[--stack.top]<<" ";
}
}
while(stack.top!=0)
{
cout<<stack.data[--stack.top]<<" ";
}
// 0 2 4 6 8 9 7 5 3 1
return 0;
}