p66-5
#define MaxSize 100
#define ElemType int
typedef struct {
ElemType stack[MaxSize];
int top[2];
} ShareStack;
ShareStack s;
int Push(ElemType e, int stackNum) {
if (stackNum < 0 || stackNum > 1) {
return 0;
}
if (s.top[1] - s.top[0] == 1) return 0;
switch (stackNum) {
case 0:
s.stack[++s.top[0]] = e;
break;
case 1:
s.stack[--s.top[1]] = e;
}
return 1;
}
ElemType Pop(int stackNum) {
if (stackNum < 0 || stackNum > 1) {
return 0;
}
if (s.top[1] - s.top[0] == 1) return 0;
switch (stackNum) {
case 0:
if (s.top[0] == 0)return 0;
return s.stack[s.top[0]--];
case 1:
if (s.top[1] == MaxSize)return 0;
return s.stack[s.top[1]++];
}
}