adt::Stack
-- abstract data type
``Stack''adt::Stack
implements the abstract data type
``Stack''.
adt::Stack(stack)
stack |
- | an expression sequence of objects to initialize the stack |
an object of the domain adt::Stack
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 builded.The methods of all abstract datatypes must be called especially and will result changing the object itself as sideeffect.
S := adt::Stack()
an empty stack is builded and
assigned to the variable S
.Stack
followed by a
number. This name is generated by genident
.All following methods changes the value of
S
itself. A new assignment to the variable (in this
example S
) is not necessary, in contrast to all other
MuPAD functions and data types.
depth
, empty
,
pop
, push
, reverse
and
top
are available for handling with stacks.S::depth()
S::pop(x)
x
at the top of the
stack.S::push()
S::reverse()
S::top()
Create a new stack with strings as arguments.
>> S := adt::Stack("1", "2", "3", "4")
Stack1
Show the length of the stack.
>> S::depth()
4
Fill up the stack with a new element. The stack will be
changed by the method, no new assignment to S
is
necessary!
>> S::push("5")
"5"
Show the top of the stack. This method does not change the stack.
>> S::top(), S::top()
"5", "5"
After twice getting an element of the stack, the third
element is the new top of the stack, and the length is
3
.
>> S::pop(), S::pop(), S::top(), S::depth()
"5", "4", "3", 3
Now revert the stack. The last element will be the first element.
>> S::reverse(): S::top()
"1"
Fill up the stack with "0"
.
>> S::push("0"): S::empty()
FALSE
Finally collect all elements of the stack in the list
assigned to ARGS
, until the stack is empty.
>> ARGS := []: while not S::empty() do ARGS := append(ARGS, S::pop()) end: ARGS
["0", "1", "2", "3"]