#include <bits/stdc++.h>
using namespace std;
#define StackSize 100
typedef int DataType;
typedef struct
{
DataType stack[StackSize];
int top;
} SeqStack;
void InitStack(SeqStack *S)//初始化栈
{
S->top = 0;
}
int StackEmpty(SeqStack S)//判断栈是否为空
{
if(S.top==0)
return 1;
else
return 0;
}
int GetTop(SeqStack S,DataType *e)//取出一个元素
{
if(S.top<=0)
{
cout<<"栈为空"<<endl;
return 0;
}
else
{
*e = S.stack[S.top-1];
return 1;
}
}
int PushStack(SeqStack *S,DataType e)//进栈操作
{
if(S->top>=StackSize)
{
cout<<"栈已满"<<endl;
return 0;
}
else
{
S->stack[S->top] = e;
S->top++;
return 1;
}
}
int PopStack(SeqStack *S,DataType *e) //出栈操作
{
if(S->top==0)
{
cout<<"栈为空"<<endl;
return 0;
}
else
{
S->top--;
*e = S->stack[S->top];
return 1;
}
}
int StackLength(SeqStack S)//返回栈长度
{
return S.top;
}
void ClearStack(SeqStack *S)//清空栈
{
S->top = 0;
}
int main()
{
SeqStack zhan;
InitStack(&zhan);
for(int i=1;i<8;i+=2)
{
PushStack(&zhan,i);
}
cout<<StackLength(zhan)<<endl;
for(int i=0;i<4;i++)
{
DataType a;
PopStack(&zhan,&a);
cout<<a<<endl;
}
ClearStack(&zhan);
return 0;
}