#include<iostream>
#include<stdio.h>
#define MAXSIZE 50
typedef struct
{
int data[MAXSIZE];
int top;
} SqStack;
// 初始化栈
void InitStack(SqStack &s)
{
s.top=-1;
}
//判断栈空
bool StackEmpty(SqStack &s)
{
if(s.top==-1)
{
return true;
}
else
{
return false;
}
}
//入栈
bool Push(SqStack &s,int x)
{
if(s.top==MAXSIZE-1)
{
return false;
}
s.data[++s.top]=x;//先加1 然后再入栈
return false;
}
//出栈
bool pop(SqStack &s,int &x)
{
if(s.top==-1)
{
return false;
}
x=s.data[s.top--];//先出栈 然后指针再减1
return false;
}
//获得栈顶元素
bool GetTop(SqStack &s,int &x)
{
if(s.top==-1) return false;
x=s.data[s.top];
return true;
}
int main()
{
SqStack stack;
InitStack(stack);
int number[]={1,2,3,4,5};
for(int i=0;i<5;i++)
{
Push(stack,number[i]);
}
int n;
for(int i=0;i<5;i++)
{
pop(stack,n);
printf("%d\n" ,n);
}
}