Skip to content
FutureBlitz

    Install

    Import std.collections.stack

    std.collections.stack

    A last-in, first-out stack.

    Push puts a value on top, and Pop takes the top one off.

    std/collections/stack.fb

    Types

    Stack class

    @DebugElements Public Class Stack<T> Implements Iterable<T>, Cloneable, Defaultable

    Last in, first out: Push puts a value on top, and Pop takes the top one off.

    Examples

    Local stack = Stack<Int>()
    stack.Push(1)
    stack.Push(2)
    Expect(stack.Pop() == 2)
    Expect(stack.Count == 1)

    std/collections/stack.fb, line 20

    • Public Property Count: Int property #

      How many values it holds.

    • Public Method Push(value: T) method #

      Puts value on top.

    • Public Method Add(value: T) method #

      The same as Push.

    • Public Method AddAll(values: Iterable<T>) method #

      Pushes each of the values, in order, so the last ends up on top.

    • @PanicsAtCaller Public Method Pop(): T method #

      Takes the top value off and gives it. Panics when the Stack is empty.

    • @PanicsAtCaller Public Method Peek(): T method #

      The top value, which stays. Panics when the Stack is empty.

    • Public Method TryPop(): T? method #

      Takes the top value off and gives it, or Null when the Stack is empty.

    • Public Method TryPeek(): T? method #

      The top value, which stays, or Null when the Stack is empty.

    • Public Method ToArray(): T[] method #

      The values from the top down, the order Pop gives them, in a new array.

    • Public Method Contains(value: T): Bool method #

      Whether it holds value.

    • Public Method Clear() method #

      Takes every value off.

    • Public Static Method DefaultValue(): Stack<T> static method #

      A new, empty Stack.

    • Public Method Clone(): Stack<T> method #

      A new Stack with the same values.

    • Public Method Iterate(): StackIterator<T> method #

      The values from the top down, the order Pop gives them. Changing the Stack while going over them panics.

    StackIterator struct

    Public Struct StackIterator<T> Implements Iterator<T>

    The values of a Stack, from the top down, which a For loop goes over.

    std/collections/stack.fb, line 112

    • @PanicsAtCaller Public ByRef Method Next(): T? method #

      The next value, from the top down, or Null after the bottom one. Panics when the Stack changed since the loop began.

    Report an issue with this page or with FutureBlitz on GitHub.