MPS 2021.1 Help

Stack

A simple stack abstraction, backed by linked list.

Stack type

stack< Type >

Subtypes

Supertypes

Comparable types

deque< Type >

sequence< Type >

java.util.Deque<Type>

Stack creation

new linkedlist

Parameter type

Result type

Type...
sequence<? extends Type >

stack< Type >

Creates an empty stack. Optionally, initial values may be specified right in the new linked list creation expression.

stack<string> test = new linkedlist<string> {"A", "B", "C"};


Alternatively, a sequence may be specified that is used to copy elements from.

stack<Type> = new linkedlist<Type> (sequence);

Operations on stack

iterator

Operand type

Parameter type

Result type

sequence< Type >

none

modifying_iterator< Type >

This operation is redefined for stack to return a modifying_iterator.

addFirst / push

Operand type

Parameter type

Result type

stack< Type >

Type

Type

Appends an element to the head of the stack.

set.addFirst (value); set.push (value);

removeFirst / pop

Operand type

Parameter type

Result type

stack< Type >

 

Type

Removes an element from the head of the stack.

set.removeFirst (value); set.pop (value);

first / peek

Operand type

Parameter type

Result type

stack< Type >

 

Type

Retrieves the first element at the head of the stack without removing it.

set.first (); set.peek ();
Last modified: 23 March 2021