icsad 2022-03-27 20:44 采纳率: 87.5%
浏览 23
已结题

请问一下我的结构体有问题吗?


#include<iostream>
#include<stack>
using namespace std;
#define MAXSIZE 100
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int SElemType;

Typedef struct 
{
    SElemType *base;
    SElemType *top;
    int stacksize;
}SqStack;


Status InitStack(SqStack &S){
    S.base=new SElemType[MAXSIZE];
    if(!S.base)
        exit(OVERFLOW);
    S.top=S.base;
    S.stacksize=MAXSIZE;
    return OK;
}

Status Push(SqStack &s,SElemType e){
    if(S.top-S.base>=MAXSIZE)
        return ERROR;
    *S.top=e;
    S.top=S.top+1;
    return OK;
}

Status Pop(SqStack &S,SElemType &e){
    if(S.top==S.base)
        return ERROR;
    S.top=S.top-1;
    e=*S.top;
}

img


这是报错的内容

  • 写回答

1条回答 默认 最新

  • qzjhjxj 2022-03-27 21:30
    关注

    修改处见注释,供参考:

    #include<iostream>
    #include<stack>
    using namespace std;
    #define MAXSIZE 100
    #define OK 1
    #define ERROR 0
    #define OVERFLOW -2
    typedef int SElemType;
    typedef int Status;    //修改
    typedef struct sqstack //Typedef struct 修改
    {
        SElemType *base;
        SElemType *top;
        int stacksize;
    }SqStack;
    
    
    Status InitStack(SqStack &S){
        S.base=new SElemType[MAXSIZE];
        if(!S.base)
            exit(OVERFLOW);
        S.top=S.base;
        S.stacksize=MAXSIZE;
        return OK;
    }
    
    Status Push(SqStack &S,SElemType e){ //SqStack &s, 修改
        if(S.top-S.base>=MAXSIZE)
            return ERROR;
        *S.top=e;
        S.top=S.top+1;
        return OK;
    }
    
    Status Pop(SqStack &S,SElemType &e){
        if(S.top==S.base)
            return ERROR;
        S.top=S.top-1;
        e=*S.top;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月4日
  • 已采纳回答 3月27日
  • 创建了问题 3月27日

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数