stack overflow underflow

时间:2023-03-10 07:17:47
stack overflow underflow

Introduction to algorithms / Thomas H. Cormen...[etal.].—3rded.

If we attempt to pop an empty stack, we say the stack underflows, which is normally an error.If S.top exceeds n, the stack overflows.
STACK-EMPTY(S)
if S.top ==
return TRUE
else return FALSE PUSH(S, x)
S.top = S.top +
S[S.top] = x POP(S)
if STACK-EMPTY(S)
error 'underflow'
else S.top = S.top -
return S[S.top + ]
//we can implement  a stack of at mostnelements withan arraySŒ1::n.
DIY-FULL(S)
if S.top < n
return FLASE
else return TRUE DIY-POP(S)
if STACK-EMPTY(S)
error 'underflow'
else if DIY-FULL(S)
error 'overflow'
else S.top = S.top -
return S[S.top + ]