Abstract datatype “Stack”
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
adt::Stack implements the abstract data type
“Stack.” To create a stack, an expression sequence of
any MuPAD® objects can be given to initialize the stack, otherwise
an empty stack is built.
adt::Stack, like those of all
abstract data types, change their argument as a side effect.
S := adt::Stack() an empty stack is
built and assigned to the variable
All following methods change the value of
A new assignment to the variable (in this example
is not necessary, in contrast to most other MuPAD functions and
The stacks created in a session are named
Stack1, Stack2,... and
printed as such.
We create an empty stack, and fill it with some values:
S := adt::Stack(); S::push(a): S::push(b): S::push(c):
The stack now contains 3 elements:
The top of the stack is the last valued pushed:
Now, we fetch successively the values contains in
they come back in reversed order:
S::pop(); S::pop(); S::pop()
Now, the stack is empty. Trying to pop again an element from
it results in a
An expression sequence of objects to initialize the stack
Object of the domain
S::empty— I the stack empty
S::nops— Size of the stack
S::depth— Depth of the stack
S::top— Top element of the stack
S::push— Push an element on the stack
S::pop— Pop an element from the stack
S::reverse— Revert the stack
S::copy— Copy of the stack