#include <stdio.h>
const int TRUE = 1;
const int FALSE = 0;
typedef int SElementType;
typedef struct
{
int top[2];
int bottom[2];
SElementType *v;
int arr_len;
}DbStack;
int StackInit(DbStack &S, int len);
int IsEmptyStack0(DbStack S);
int IsEmptyStack1(DbStack S);
int FullStack(DbStack S);
int Stack0Push(DbStack &S, SElementType e);
int Stack1Push(DbStack &S, SElementType e);
SElementType Stack0Pop(DbStack &S);
SElementType Stack1Pop(DbStack &S);
int main()
{
}
int StackInit(DbStack &S, int len)
{
S.max_size = len;
S.v = new ElementType [len];
if(!S.v)
{
printf("\n申请空间失败!");
return FALSE;
}
S.bottom[0] = S.top[0] = -1;
S.bottom[1] = S.top[1] = len;
return TRUE;
}
int IsEmptyStack0(DbStack S)
{
if(S.top[0] == -1)
{
return TRUE;
}
else
{
return FALSE;
}
}
int IsEmptyStack1(DbStack S)
{
if(S.top[1] == S.arr_len)
{
return TRUE;
}
else
{
return FALSE;
}
}
int FullStack(DbStack S)
{
if(S.top[1] - S.top[0] == 1)
{
return TRUE;
}
else
{
return FALSE;
}
}
int Stack0Push(DbStack &S, SElementType e)
{
if(FullStack(S))
{
printf("\nStack0入栈失败!");
return FALSE;
}
S.top[0]++;
S.v[S.top[0]] = e;
}
int Stack1Push(DbStack &S, SElementType e)
{
if(FullStack(S))
{
printf("\nStack1入栈失败!");
return FALSE;
}
S.top[1]++;
S.v[S.top[1]] = e;
return TRUE;
}
int Stack0Pop(DbStack &S, ElementType &e)
{
if(S.top[0] != -1)
{
e = S.v[top[0];
S.top[0]--;
return TRUE;
}
else
{
return FALSE;
}
}
int Stack1Pop(DbStack &S, ElementType &e)
{
if(S.top[1] != S.arr_len)
{
e = S.v[S.top[1]];
S.top[1]--;
return TRUE;
}
else
{
return FALSE;
}
}