题解 | #逆序输出(栈)#
逆序输出
https://www.nowcoder.com/practice/bb66c27cb7aa48f9ba7d9f88e4068285
#include <stdio.h> #include<stdlib.h> #define Maxsize 50 typedef struct Stack { int data[Maxsize]; int top }SqStack; // 入栈操作 void Push(SqStack* S, int x) { if (S->top == Maxsize) { } S->data[++S->top] = x; } //出栈操作(栈,操作数); int Pop(SqStack* S, int* x) { x = &S->data[S->top--]; return *x; } int main() { int a, b; SqStack S; for (int i = 0; i < 10; i++) { scanf("%d ", &a); Push(&S,a); } for (int i = 0; i < 10; i++) { printf("%d ",Pop(&S,&a)); } return 0; }