stack - Maple Help

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

 • Important: The stack command has been deprecated. Use the superseding command DEQueue instead.
 • 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

Important: The stack command has been deprecated. Use the superseding command DEQueue instead.

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