void minStackPop(MinStack *stack) { int iTopValue = 0; Element *pstElement = NULL; if (NULL == stack || !stack->iCurSize) { return; } iTopValue = minStackTop(stack); /* Pop top */ stack->iCurSize --; (stack->pstElement + stack->iCurSize)->iValue = 0; /* Get new min value */ if (iTopValue == stack->iMinValue) { pstElement = stack->pstElement; stack->iMinValue = pstElement->iValue; for (int i=1; i < stack->iCurSize; i ++) { if ((pstElement + i)->iValue < stack->iMinValue) { stack->iMinValue = (pstElement + i)->iValue; } } } }
void minStackPop(MinStack *stack) { int top = minStackTop(stack); if(top <= minStackGetMin(stack)) stack->top_min--; stack->top_data--; }
int minStackGetMin(MinStack *stack) { int cur_min = minStackTop ( stack ) ; int temp_size = stack->cur_size; while ( temp_size > 0 ) { if ( stack->data [ temp_size - 1 ] < cur_min ) { cur_min = stack->data [ temp_size - 1 ]; } temp_size -= 1; } return cur_min; }