1644: 栈-初始化、入栈和打印1(顺序存储)
金币值:2
定数:8
时间限制:1.000 s
内存限制:128 M
正确:47
提交:115
正确率:40.87% 命题人:
题目描述
初始化一个栈(假设栈顶指针和栈底指针相等时为空栈),用入栈操作输入一些元素(元素的个数不超过栈的长度),然后打印输出这些元素。
输入格式
第1行输入一个整数n,表示栈中数据元素的个数
第2行输入n个整数,表示栈中的元素
输出格式
第3行按照输入顺序逆序输出n个整数
输入样例 复制
4
1 2 3 4
输出样例 复制
4 3 2 1
提示
#include "stdio.h" #define MAXSIZE 100 typedef int elemType; typedef struct { elemType *base; elemType *top; int stacksize; } sqStack; void init(sqStack &s); void push(sqStack &s, elemType x); void input(sqStack &s); void output(sqStack s); int main(void) { sqStack s; init(s); input(s); output(s); return 0; } void init(sqStack &s) { } void push(sqStack &s, elemType x) { if(s.top-s.base==s.stacksize) { printf("stack is full!\n"); } else { } } void input(sqStack &s) { int n; elemType x; scanf("%d",&n); for(int i=1; i<=n; i++) { scanf("%d",&x); push(s,x); } } void output(sqStack s) { for(int *p=s.top-1; p>=s.base; p--) { } }