![stack overflow underflow stack overflow underflow](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
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 + ]