#include <iostream>
#include <stdlib.h>
#define MAX_SIZE 100
typedef int ElemType;
typedef struct //定义栈结构体
{
int top0;
int top1;
ElemType data[200];
}SqStack;
void InitStack(SqStack *&s) //初始化栈
{
s=(SqStack *)malloc(sizeof(SqStack));
s->top0=-1;
s->top1=99;
}
int Push(SqStack *s,int i,int e) //进栈,int i来选择是在那个栈进行,0是在栈0,1表示在栈1
{
if(i==0)
{
if(s->top0==99)
return false;
s->top0++;
s->data[s->top0]=e;
return true;
}
else if(i==1)
{
if(s->top1==199)
return false;
s->top1++;
s->data[s->top1]=e;
return true;
}
else
printf("type is wrong/n");
return 0;
}
int Pop(SqStack *s,int i,int e) //出栈同上例
{
if(i==0)
{
if(s->top0==-1)
return false;
e=s->data[s->top0];
s->top0--;
}
else if(i==1)
{
if(s->top1==99)
return false;
e=s->data[s->top1];
s->top1--;
}
else
printf("pop type is wrong/n");
return 0;
}
int main()
{
ElemType e;
int i;
SqStack *s=NULL;
InitStack (s);
printf("input int to push :/n");
scanf("%d",&e);
printf("input which stack:(i=0,1?)/n");
scanf("%d",&i);
printf("your choose int %d to push in %d/n",e,i);
Push(s,i,e);
switch (i)
{
case 0:
printf("ruzhan zhi %d/n",s->data[s->top0]);
break;
case 1:
printf("ruzhan zhi %d/n",s->data[s->top1]);
break;
default:
printf("error/n");
break;
}
printf("input which stack:(i=0,1?)/n");
scanf("%d",&i);
Pop(s,i,e);
printf("chu zhan de shi %d/n",e);
free(s);
return 0;
}