v2026.2.1
All Bundles

Stack

Growable stack of generics (LIFO)

stack := Collection.Stack->New()<IntRef>;
stack->Push(1);
stack->Push(2);
stack->Push(3);
stack->Pop()->PrintLine();  # prints 3
stack->Top()->PrintLine();  # prints 2
stack->Size()->PrintLine(); # prints 2

Operations

Empty

Clears the stack

method : public : Empty() ~ Nil

IsEmpty

Checks to see if the stack is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

New

Default constructor

New()

Pop

Pops values from the stack

method : public : native : Pop(n:Int) ~ H

Parameters

NameTypeDescription
nIntnumber of items to pop

Return

TypeDescription
Hpopped valued, Nil if stack is empty

Pop

Pops a value from the stack

method : public : Pop() ~ H

Return

TypeDescription
Hpopped valued, Nil if stack is empty

Push

Pushes a value onto the stack

method : public : Push(value:H) ~ Nil

Parameters

NameTypeDescription
valueHto push

Size

Size of stack

method : public : Size() ~ Int

Return

TypeDescription
Intsize of stack

ToArray

Converts the stack into an object array

method : public : native : ToArray() ~ H[]

Return

TypeDescription
H[]object array

ToString

Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.

method : public : ToString() ~ String

Return

TypeDescription
Stringstring representation

Top

Check the top of the stack

method : public : Top() ~ H

Return

TypeDescription
Hvalue on the top of stack, Nil if stack is empty