![](https://img-blog.csdnimg.cn/direct/ae6900503a5b4072aa5eeb6b7d988542.png)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define max_size 100
typedef int ElemType;
typedef struct SqStack {
ElemType data[max_size];
int top;
}SqStack;
void initial(SqStack& S) {
S.top = 0;
}
bool isEmpty(SqStack S) {
if (S.top == 0) {
return true;
}
return false;
}
bool Push(SqStack& S, ElemType e) {
if (S.top == max_size) {
return false;
}
S.data[++S.top] = e;
return true;
}
bool Pop(SqStack& S, ElemType& e) {
if (S.top == 0) {
return false;
}
e = S.data[S.top--];
return true;
}
int main() {
SqStack S;
SqStack S2;//保存输出元素
initial(S2);
initial(S);
int arr[max_size] = { 0 };
int len = 0;
while (scanf("%d", &arr[len])&&arr[len]!=-2) {
len += 1;
}
ElemType num;
for (int i = 0; i < len; i++) {
if (arr[i] != -1) {
Push(S, arr[i]);
}
else {
Pop(S, num);
}
}
while (!isEmpty(S)) {
Pop(S, num);
Push(S2, num);
}
while (!isEmpty(S2)) {
Pop(S2, num);
printf("%d ", num);
}
return 0;
}