在做力扣最小栈时用了这样一个办法:
int max=99
typedef struct StackNode{
int data;
int min;
struct StackNodenext;
} MinStack;
MinStack minStackCreate() {
MinStackobj=(MinStack)malloc(sizeof(MinStack));
obj->min=max;
obj->next=NULL;
return obj;
}
void minStackPush(MinStack* obj, int x) {
MinStack* p=(MinStack*)malloc(sizeof(MinStack));
p->data=x;
if(xmin) p->min=x;
else p->min=obj->min;
p->next=obj;
obj=p;
}
void minStackPop(MinStack* obj) {
if(obj->next==NULL) return;
MinStackL=obj;
obj=obj->next;
free(L);
L=NULL;
}
int minStackTop(MinStack obj) {
return obj->data;
}
int minStackGetMin(MinStack* obj) {
return obj->min;
}
void mi
C语言错误:函数内变量的赋值出了函数就没了
最新推荐文章于 2023-03-15 13:04:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)