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