#include <stdio.h>
#include <stdlib.h>
#define maxsize 100
typedef int datatype;
typedef struct
{
datatype stack[maxsize];
int top1;
int top2;
}seqstack;
seqstack *s;
void initstack()
{
if(!s);
else
{s->top1=-1;
s->top2=maxsize;
}
}
void push1(seqstack *q,datatype x)
{
if(q->top1==s->top2);
else
{
s->top1++;
s->stack[s->top1]=x;
}
}
void push2(seqstack *q,datatype x)
{
if(q->top2==s->top1);
else
{
s->top2--;
s->stack[s->top2]=x;
}
}
datatype pop(seqstack *q)
{
if(s->top1==0&&s->top2==maxsize-1) return 0;
if(q->top1==s->top1)
{
s->top1--;
return s->stack[s->top1+1];
}
if(q->top2==s->top2)
{
s->top2++;
return s->stack[s->top2-1];
}
}
int stackempty()
{
if(s->top1==-1&&s->top2==maxsize) return 1;
else return 0;
}
void display()
{
int t,r;
t=s->top1;
r=s->top2;
if(s->top1==-1 )printf("s1 is empty!");
else
{printf("\ns1:");
while(t!=-1)
{t--;
printf("%d ",s->stack[t]);
}
}
if(s->top2==maxsize)printf("s2 is empty!");
else
{
printf("\ns2:");
while(r!=maxsize)
{
r++;
printf("%d ",s->stack[r]);
}
}
}
int main()
{
initstack();
seqstack *s1,*s2;
s1=s;
s2=s;
s1->top2=-2;
s2->top1=-2;
int a[6]={1,2,3,4,5,6};
int i;
int b[5]={9,8,7,6,5};
for(i=0;i<6;i++) push1(s1,a[i]);
for(i=0;i<5;i++) push2(s2,b[i]);
printf("output the stack:");
display();
}