Abstract datatype "Stack"
This functionality does not run in MATLAB.
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.
Note: The methods adt::Stack, like those of all abstract data types, change their argument as a side effect.
With S := adt::Stack() an empty stack is built and assigned to the variable S.
Note: All following methods change the value of S itself. A new assignment to the variable (in this example S) is not necessary, in contrast to most other MuPAD functions and data types.
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 S; 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 FAIL value being returned:
An expression sequence of objects to initialize the stack