//栈
//顺序存储
//定义
const int maxsize=6;
typedef struct seqstack
{
DataType data[maxsize];
int top;
}SeqStk;
//1.初始化
int InitStack(SeqStk *stk)
{
stk->top=0;
return 1;
}
//2.判栈空
int EmptyStack(SeqStk *stk)
{
if (stk->top==0)
return 1;
else
return 0;
}
//3.进栈
int Push(SeqStk *stk,DataType x)
{
if (stk->top==maxsize-1)
{
error("stack full!");
return 0;
}
else
{
stk->top++;
stk->data[stk->top]=x;
return 1;
}
}
//4.出栈
int Pop(SeqStk *stk)
{
if (EmptyStack(stk))
{
error("underflow!");
return 0;
}
else
{
stk->top--;
return 1;
}
}
//5.取栈顶元素
DataType GetTop(SeqStk *stk)
{
if (EmptyStack(stk))
return NULLData;
else
return stk->data[stk->top];
}