Stack Functions

A stack is a last-in, first-out (LIFO) data structure. Use CreateStack to create one, then Push, Pop, and Peek to work with it.


CreateStack

CreateStack()

Creates and returns a new empty stack object.

Returns: Stack

Examples:

Dim s = CreateStack()

Push

Push(Stack, Value)

Adds Value to the top of Stack.

Parameter Description
Stack A stack created by CreateStack
Value The value to push onto the stack

Returns: Boolean (True on success)

Examples:

Push(s, 10)
Push(s, "Hello")

Pop

Pop(Stack)

Removes and returns the top item from Stack. The stack must not be empty.

Returns: Object (the removed value)

Examples:

Dim top = Pop(s)

Peek

Peek(Stack)

Returns the top item from Stack without removing it.

Returns: Object

Examples:

Dim top = Peek(s)

Example: Using a Stack

Dim s = CreateStack()
Push(s, 1)
Push(s, 2)
Push(s, 3)

Dim a = Pop(s)    ' 3
Dim b = Pop(s)    ' 2
Dim c = Pop(s)    ' 1