堆栈_顺序存储_数组双栈
#include<bits\stdc++.h>
using namespace std;
#define MaxSize 100
typedef struct SNode *Stack;
struct SNode{
int Data[MaxSize];
int Top1;
int Top2;
}S;
S.Top1=-1;
S.Top2=MaxSize;
void Push(Stack PtrS,int item,int Tag)
{
if(PtrS->Top2 - PtrS->Top1==1)
{
cout<<"栈满"; return;
}
if(Tag==1)
PtrS->Data[++(PtrS->Top1)]=item;
else
PtrS->Data[--(PtrS->Top2)]=item;
}
int Pop(Stack PtrS,int Tag)
{
if(Tag==1)
{
if(PtrS->Top1==-1)
{
cout<<"栈空";
return -1;
}
return PtrS->Data[(PtrS->Top1)--];
}
if(Tag==2)
{
if(PtrS->Top2==MaxSize)
{
cout<<"栈空";
return -1;
}
return PtrS->Data[(PtrS->Top2)++];
}
}
int main()
{
return 0;
}