Status StackEmpty(SqStack S)

Status StackEmpty(SqStack S) {
	if (S.base == S.top)
		return OK;
	else
		return ERROR;
}
3. 数据结构和ACM2023-第三章-栈-创建堆栈 - LJD 【问题描述】 堆栈的基本操作 从键盘读入n个整数,依次放入堆栈中,之后再将整数从堆栈弹出并打印。 要求使用顺序栈 【输入形式】 整数个数n n个整数(以空格分隔) 【输出形式】 逆序输出堆栈的所有元素,输出元素的个数 【样例输入】 3 1 2 3 【样例输出】 3 2 1 3 【样例说明】 【代码框架】 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #define ERROR 0 #define OK 1 #define TRUE 1 #define FALSE 0 typedef int ElemType; typedef int Status; // definition of array based stack #define STACK_INIT_SIZE 100 //Initial size for memory allocation #define STACKINCREMENT 10 //incremental size typedef struct{ ElemType *base; //base pointer ElemType *top; //top pointer int stacksize; //current size }SqStack; //========================================== // initialization of array-based stack //=========================================== Status InitStack(SqStack *S) { //学生添加程序 } //======================================== //Test empty stack //======================================== Status StackEmpty (SqStack S) { //学生添加程序 } //=============================================== // Get the length of a stack //============================================== int StackLength (SqStack S) { //学生添加程序 } //===================================== // Get top item of a stack //==================================== Status GetTop(SqStack S, ElemType *e) { //学生添加程序 } //=================================================== // Delete an item from the stack //==================================================== Status Pop(SqStack *S,ElemType *e) { //学生添加程序 } //====================================== // Insert an item into the stack //======================================= Status Push(SqStack *S,ElemType e) { //学生添加程序 } //====================================== // Print the elements in a stack //======================================= void PrintStack (SqStack S) { //学生添加程序 } //====================================== // 逆序输出堆栈的所有元素,并返回输出元素的个数 //======================================= int reverseOutput(SqStack *S) { int len=StackLength(*S); int e; while(StackEmpty(*S)) { Pop(S,&e); printf("%d ",e); } printf("\n"); printf("%d\n",len); return len; } int main() { SqStack S; int num; int i; int e; InitStack(&S); scanf("%d",&num); for(i=0;i<num;i++) { scanf("%d",&e); Push(&S,e); } reverseOutput(&S); return 1; }
最新发布
03-31
这个题怎么写题目描述 对于输入的任意一个非负十进制整数N,打印输出与其等值的m进制数。 本题特别说明: 1)我们以此题作为栈的入门级验证性实验,如果是实验课,请不要采用其它优化算法,老老实实按照数据结构(C语言版)教材p46-p48页上的类C代码进行改编。 2)关键是要仿照教材p46-p48页上的类C代码,编写初始化栈、入栈、出栈及判断栈空等函数。 3)类C代码99%可以照抄,主要是要注意类C代码各函数形参中的符号“&”--属于C++语言中的引用。在VC中调试时,如果文件扩展名为.c,则要遵循C语法规则,对于“&”不能照抄,“&”只能作为求地址运算符,因此,需要改编,实际上只要保证“传地址”就行了。如果文件扩展名为.cpp,则可按C++语法编写程序,“&”可作为引用运算符,因此“&”可以照抄...... 4)扩展名为.CPP的程序的总体框架,提示如下,仅供参考。 #include<stdio.h> #include<malloc.h> #include<stdlib.h> #define OK 1 #define ERROR 0 #define OVERFLOW -2 #define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 typedef int Status; typedef struct { int *base; int *top; int stacksize; }SqStack; SqStack S; Status InitStack(SqStack &S) { //...... return OK; } Status Push(SqStack &S, int e) { //...... return OK; }//Push Status Pop(SqStack &S, int *e) { //...... return OK; }//Pop Status StackEmpty(SqStack &S) { //...... } void conversion() { int N,m; int e; InitStack(S); while(scanf("%d,%d",&N,&m)!=EOF) { //...... } } int main() { conversion(); return 0; }
03-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时光_Bayzhen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值