Stack

open class Stack<T>(elements: Collection<T>)

Stack represents a Last In First Out (LIFO) data structure. It provides useful functions to manipulate the Stack.

Constructors

Link copied to clipboard
fun <T> Stack(vararg element: T)

Creates a Stack with vararg initial elements.

Link copied to clipboard
fun Stack()

Creates an empty Stack.

Link copied to clipboard
fun <T> Stack(elements: Collection<T>)

Creates a Stack with, given initial elements.

Functions

Link copied to clipboard
fun clear(): List<T>

Pops all elements in this Stack and returns them in a List, with the topmost element as the list's head i.e. index 0.

Link copied to clipboard
fun indexOf(element: T): Int

Returns the index of the first occurrence of the specified element in the Stack, or -1 if the specified element is not contained in the Stack.

Link copied to clipboard
fun isEmpty(): Boolean

Returns whether this Stack is empty or not.

Link copied to clipboard
fun isNotEmpty(): Boolean

Returns whether this Stack is not empty.

Link copied to clipboard
fun peek(): T

Returns the topmost element in this Stack but does not pop it.

Link copied to clipboard
fun peekAll(numToPeek: Int = data.size): List<T>

Returns all elements in this Stack, with the last pushed Element at the highest index.

Link copied to clipboard
fun peekOrNull(): T?

Returns the topmost element in this Stack but does not pop it.

Link copied to clipboard
fun pop(): T

Pops the topmost element in this Stack.

Link copied to clipboard
fun popAll(numToPop: Int = data.size): List<T>

Pops the n topmost elements in this Stack, where n is specified by the parameter. The topmost element in the stack gets the list's head i.e. index 0.

Link copied to clipboard
fun popOrNull(): T?

Pops the topmost element in this Stack.

Link copied to clipboard
fun push(element: T)

Pushes the supplied element onto the Stack.

Link copied to clipboard
fun pushAll(vararg elements: T)

Pushes all the supplied elements onto the Stack. The first parameter is pushed first.

fun pushAll(elements: Collection<T>)

Pushes all the supplied elements onto the Stack. The element at index 0 of the List is pushed first.

Link copied to clipboard
fun shuffle()

Shuffles this Stack.

Link copied to clipboard
fun sort(comparator: Comparator<in T>)

Sorts this Stack.

Properties

Link copied to clipboard
val size: Int

Size of this Stack.