Skip to content

Stack

1 min read

Import: import system.collections;

Read the usage guide for examples and common tasks. This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation.

Stack

LIFO stack backed by List<T>.

public class Stack<T>: Collection<T>

constructor

Creates an empty stack.

public constructor()

length

Number of elements currently stored.

public get length(): int

push

Pushes value onto the top of the stack.

public fun push(value: T): void

pop

Removes and returns the top element, or None when empty.

public fun pop(): Option<T>

peek

Returns the top element without removing it, or None when empty.

public fun peek(): Option<T>

clear

Removes every element.

public fun clear(): void

iterator

Iterates elements from bottom to top.

public fun iterator(): ListIterator<T>