Beruflich Dokumente
Kultur Dokumente
Session: Stacks
• pop(S)
• pop(Ф) = undefined (will give an error if executed)
• pop(push(x,S)) = S
• top(S)
• top(Ф) = undefined
• top(push(x,S)) = x
• Only these operations are allowed for a variable of stack
type
valid(Ф,S2) = empty(S2)
valid(push(‘(‘,S1),S2) = valid(S1, push(‘(‘,S2))
valid(push(‘)’,S1),S2) = false if empty(S2)
= valid(S1,pop(S2)) otherwise
balanced(S) = valid(S,Ф)
• Note that we use the allowed operations on the stack
variable. This simplifies description of more complicated
functions built using a stack.