Documentation

This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

adt::Stack

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.

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`

Methods

expand all

`S::empty()`

`S::nops()`

`S::depth()`

`S::top()`

`S::push(x)`

`S::pop()`

`S::reverse()`

`S::copy()`

Was this topic helpful?

Watch now