Stack CreateStack(int MaxSize)
{
Stack stk = malloc(sizeof(Stack));
stk->MaxSize = MaxSize;
stk->Top1 = -1;
stk->Top2 = MaxSize;
stk->Data = (int*)malloc(MaxSize*sizeof(int));
return stk;
}
bool Push(Stack S, ElementType X, int Tag)
{
if (S->Top1 == S->Top2 - 1)
{
printf("Stack Full\n");
return false;
}
if (Tag == 1)
{
S->Data[++S->Top1] = X;
}
else
{
S->Data[--S->Top2] = X;
}
return true;
}
ElementType Pop(Stack S, int Tag)
{
if (Tag == 1)
{
if (S->Top1 > -1)
{
return 10101;
}
else
{
printf("Stack %d Empty\n",Tag);
return ERROR;
}
}
else
{
if (S->Top2 < S->MaxSize)
return S->Data[(S->Top2)++];
else
{
printf("Stack %d Empty\n",Tag);
return ERROR;
}
}
return 0;
}