adt::Stack

Abstract datatype "Stack"

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

adt::Stack(stack)

Description

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.

Examples

Example 1

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:

S::nops()

The top of the stack is the last valued pushed:

S::top()

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:

S::pop()

Parameters

stack

An expression sequence of objects to initialize the stack

Return Values

Object of the domain adt::Stack

Was this topic helpful?