Curvature9 2022-03-31 17:35 采纳率: 100%
浏览 342
已结题

VSCode调试时遇到闪退问题

是课程平时练习要求写的代码,在运行时遇到断点后闪退,错误提示如下图
这个问题之前也出现过,依旧是不知道怎么解决,希望能为我解答一下!

img

#include<stdio.h>
#include<stdlib.h>
typedef struct Stack
{
int *base;
int top;
int size;
int lenth;
}SqStack;
SqStack InitStack(int n)
{
SqStack L;
L=(SqStack)malloc(sizeof(Stack));
L->base=(int
)malloc(n
sizeof(int));
L->top=L->base;
L->size=n;
L->lenth=0;
return L;
}
SqStack Push(SqStack &L,int e)
{
(L->top)=e;
L->top++;
L->lenth++;
return L;
}
int Pop(SqStack &L)
{
int e;
e=
(L->top);
L->top--;
L->lenth--;
return e;
}
int GetHead(SqStack &L)
{
return *(L->top);
}
int CountByHeigt(SqStack &L)
{
int aim;
aim=Pop(L);
int cnt=0;
while(L->lenth!=0)
{
if(GetHead(L)<aim)
{
Pop(L);
cnt++;
}
else
{
aim=Pop(L);
}
}
return cnt;
}
void Destroy(SqStack &L)
{
free(L->base);
L->base=NULL;
L->top=NULL;
L->size=0;
L->lenth=0;
}
int main()
{
int num,height,count;
scanf("%d",&num);
SqStack L;
L=InitStack(num);
for(int i=0;i<num;i++)
{
scanf("%d",&height);
Push(L,height);
}
count=CountByHeigt(L);
Destroy(L);
printf("%d\n",count);
return 0;
}

  • 写回答

2条回答 默认 最新

  • 关注

    代码:

    #include<stdio.h>
    #include<stdlib.h>
    typedef struct Stack
    {
        int* base;
        int* top;
        int size;
        int lenth;
    }SqStack;
    SqStack* InitStack(int n)
    {
        SqStack* L;
        L = (SqStack*)malloc(sizeof(Stack));
        L->base = (int*)malloc(n*sizeof(int));
        L->top = L->base;
        L->size = n;
        L->lenth = 0;
        return L;
    }
    SqStack* Push(SqStack* &L, int e)
    {
        *(L->top) = e;
        L->top++;
        L->lenth++;
        return L;
    }
    int Pop(SqStack* &L)
    {
        int e;
        //修改 判断是否已经为空
        if (L->lenth == 0 || L->base == L->top)
            return -1;
    
        L->top--;
        e = *(L->top);
        L->lenth--;
        return e;
    }
    int GetHead(SqStack* &L)
    {
        return *(L->top);
    }
    int CountByHeigt(SqStack* &L)
    {
        int aim;
        aim = Pop(L); 
        int cnt = 0;
        int* p;
        while (L->lenth > 0)
        {
            p = L->top;
            p--;
            while (1)
            {
                if (*p < aim)
                {
                    cnt++;
                    if (p == L->base)
                        break;
                    else
                        p--;
                }
                else
                    break;
            }
            aim = Pop(L);
        }
        return cnt;
    }
    void Destroy(SqStack* &L)
    {
        free(L->base);
        L->base = NULL;
        L->top = NULL;
        L->size = 0;
        L->lenth = 0;
        //修改,是否L的空间
        free(L);
        L = 0;
    }
    int main()
    {
        int num, height, count;
        scanf("%d", &num);
        SqStack* L;
        L = InitStack(num);
        for (int i = 0; i < num; i++)
        {
            scanf("%d", &height);
            Push(L, height);
        }
        count = CountByHeigt(L);
        Destroy(L);
        printf("%d\n", count);
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

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

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作