#include<stdio.h>
#define M 100
typedef struct
{
int ste[M];
int top[2];
}node;
void initlist(node *s)
{
s->top[0]=-1;
s->top[1]=M;
}
void push(node *s)
{
int i,x=-1;
while(x!=0)
{
printf("请输入进栈数x和进栈号i:\n");
scanf("%d%d",&x,&i);
if(s->top[0]+1==s->top[1])
printf("栈已满!!!\n");
switch(i)
{
case 0:
s->top[0]++;
s->ste[s->top[0]]=x;
break;
case 1:
s->top[1]--;
s->ste[s->top[1]]=x;
break;
default:
printf("输入有误!!!\n");
}
}
}
void put(node *s)
{
int x,i;
printf("请输入出栈的序号i:\n");
scanf("%d",&i);
switch(i)
{
case 0:
if(s->top[0]==-1)
printf("出栈错误!!!\n");
x=s->ste[s->top[0]];
s->top[0]--;
break;
case 1:
if(s->top[1]==M)
printf("出栈错误!!\n");
x=s->ste[s->top[1]];
s->top[1]++;
break;
default:
printf("输入有误!!\n");
}
for(int t=0;t<s->top[0];t++)
{
printf("%d ",s->ste[t]);
}
for(int j=M-1;j>s->top[1];j--)
{
printf("%d ",s->ste[j]);
}
}
int main()
{
node s;
initlist(&s);
push(&s);
put(&s);
return 0;
}
#define M 100
typedef struct
{
int ste[M];
int top[2];
}node;
void initlist(node *s)
{
s->top[0]=-1;
s->top[1]=M;
}
void push(node *s)
{
int i,x=-1;
while(x!=0)
{
printf("请输入进栈数x和进栈号i:\n");
scanf("%d%d",&x,&i);
if(s->top[0]+1==s->top[1])
printf("栈已满!!!\n");
switch(i)
{
case 0:
s->top[0]++;
s->ste[s->top[0]]=x;
break;
case 1:
s->top[1]--;
s->ste[s->top[1]]=x;
break;
default:
printf("输入有误!!!\n");
}
}
}
void put(node *s)
{
int x,i;
printf("请输入出栈的序号i:\n");
scanf("%d",&i);
switch(i)
{
case 0:
if(s->top[0]==-1)
printf("出栈错误!!!\n");
x=s->ste[s->top[0]];
s->top[0]--;
break;
case 1:
if(s->top[1]==M)
printf("出栈错误!!\n");
x=s->ste[s->top[1]];
s->top[1]++;
break;
default:
printf("输入有误!!\n");
}
for(int t=0;t<s->top[0];t++)
{
printf("%d ",s->ste[t]);
}
for(int j=M-1;j>s->top[1];j--)
{
printf("%d ",s->ste[j]);
}
}
int main()
{
node s;
initlist(&s);
push(&s);
put(&s);
return 0;
}