//棧
//順序存儲
//定義
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];
}