//兩棧存儲
const int max=40;
typedef struct Dbstack
{
DataType data[max];
int top1,top2;
}DbStk;
//1.初始化
int InitStack(SeqStk *stk)
{
stk->top1=0;
stk->top2=max-1;
return 1;
}
//2.判棧空
int EmptyStack(SeqStk *stk)
{
if ((stk->top1==0)&&(stk->top2==max-1))
return 1;
else
return 0;
}
//3.進棧top1! top2同理
int Push(SeqStk *stk,DataType x)
{
if (stk->top1+1==stk->top2)
{
error("stack full!");
return 0;
}
else
{
stk->top1++;
stk->data[stk->top1]=x;
return 1;
}
}
//4.出棧top1! top2同理
int Pop(SeqStk *stk)
{
if (EmptyStack(stk))
{
error("underflow!");
return 0;
}
else
{
stk->top1--;
return 1;
}
}
//5.取棧頂元素(top1! top2同理)
DataType GetTop(SeqStk *stk)
{
if (EmptyStack(stk))
return NULLData;
else
return stk->data[stk->top1];
}