#include <stdio.h> #include <stdbool.h> #define MAXSIZE 1000 typedef int ElemType; typedef struct { ElemType data[MAXSIZE]; int top; } Stack; // 初始化一个栈: void InitStack(Stack *S) { S->top = -1; } // 栈判空: bool StackEmpty(Stack S) { if (S.top == -1) { return true; } else return false; } // 进栈: bool Push(Stack *S, ElemType x) { if (S->top == MAXSIZE - 1) return false; else { S->data[++S->top] = x; return true; } } // 出栈: bool Pop(Stack *S, ElemType *x) { if (S->top != -1) { *x = S->data[S->top--]; return true; } else return false; } // 读取栈顶元素: bool GetTop(Stack S, ElemType *x) { if (S.top == -1) return false; else { *x = S.data[S.top]; return true; } } int main() { int n; scanf("%d", &n); Stack S; InitStack(&S); int number; int Arr[n]; while (n--) { scanf("%d", &number); Push(&S, number); } int i = 0; while (S.top != -1) { Pop(&S, &number); printf("%d ", number); } printf("\n"); return 0; }