stack - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

stack

Stack Data Structure

 Calling Sequence stack[new]() stack[new](x1, ..., xn) stack[push](x, s) stack[pop](s) stack[empty](s) stack[top](s) stack[depth](s)

Parameters

 s - stack x, x[i] - values to be inserted into the stack

Description

 • The call stack[new]() returns an empty stack. The call stack[new](x1, ..., xn) returns a stack with the values x1, ..., xn on the stack with x1 on the top of the stack.
 • The call stack[push](x, s) puts x on the top of the stack s while stack[pop](s) returns (and removes) the top element from the stack.
 • The call stack[empty](s) returns true if the stack s is empty, and false if it is not empty.
 • Additionally, stack[top](s) returns the top element of the stack (but does not remove it) and stack[depth](s) returns the number of elements in the stack.
 • An object-oriented stack implementation is available via the Stack constructor.

Examples

 > $s≔\mathrm{stack}[\mathrm{new}]\left(\mathrm{greg},\mathrm{tony},\mathrm{bruno},\mathrm{michael}\right):$
 > $\mathrm{stack}[\mathrm{push}]\left(\mathrm{stefan},s\right)$
 ${\mathrm{stefan}}$ (1)
 > $\mathrm{stack}[\mathrm{depth}]\left(s\right)$
 ${5}$ (2)
 > $\mathrm{stack}[\mathrm{top}]\left(s\right)$
 ${\mathrm{stefan}}$ (3)
 > $\mathbf{while}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{not}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{stack}[\mathrm{empty}]\left(s\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{stack}[\mathrm{pop}]\left(s\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end do}$
 ${\mathrm{greg}}$ (4)

 See Also

## Was this information helpful?

 Please add your Comment (Optional) E-mail Address (Optional) What is ? This question helps us to combat spam