StackMin、Pop、Push のスタック内の最小値を取得しようとしていますΘ(1)
。私のコードは機能しません...これが私の試みです:
typedef struct{
int top;
int entry[1000];
int small;
} Stack;
void Pop(int *e,Stack *ps){
*e=ps->entry[--ps->top];
}
void Push(int e,Stack *ps){
ps->entry[ps->top++]=e;
}
int StackMin(Stack *ps){
ps->small=ps->entry[ps->top];
while(!StackEmpty(ps)){
int *e;
*e=ps->entry[--ps->top];
if(ps->small >= *e){
ps->small = *e;
}
}
return ps->small;
}