#include <iostream>
using namespace std;
constexpr int MaxSize = 10;
using ElemType = int;
struct ShStack {
ElemType data[MaxSize];
int top0;
int top1;
};
void InitStack(ShStack &S) {
S.top0 = -1;
S.top1 = MaxSize;
}
bool Stack0Empty(const ShStack &S) { return S.top0 == -1; }
bool Stack1Empty(const ShStack &S) { return S.top1 == MaxSize; }
bool StackFull(const ShStack &S) { return S.top0 + 1 == S.top1; }
bool Push0(ShStack &S, ElemType x) {
if (StackFull(S)) return false;
S.data[++S.top0] = x;
return true;
}
bool Push1(ShStack &S, ElemType x) {
if (StackFull(S)) return false;
S.data[--S.top1] = x;
return true;
}
bool Pop0(ShStack &S, ElemType &x) {
if (Stack0Empty(S)) return false;
x = S.data[S.top0--];
return true;
}
bool Pop1(ShStack &S, ElemType &x) {
if (Stack1Empty(S)) return false;
x = S.data[S.top1++];
return true;
}
int main() {
ShStack S;
InitStack(S);
for (int i = 1; i <= 6; ++i) Push0(S, i);
for (int i = 10; i >= 7; --i) Push1(S, i);
ElemType x;
while (!Stack0Empty(S)) { Pop0(S, x); cout << "左栈出: " << x ; }
while (!Stack1Empty(S)) { Pop1(S, x); cout << "右栈出: " << x ; }
return 0;
}