Reference

Stack

New

Input A list of elements.
Output A stack containing the list of elements with the last element at the top of the stack.

Signature

stack_new(a: List): Stack

Example

stack_new([1, 2, 3]) // returns a stack with 3 at the top

Push

Input A stack and an element.
Output A new stack with the element added to the top.

Signature

stack_push(a: Stack, b: Any): Stack

Example

stack_push(stack_new([1, 2]), 3) // returns a stack with 3 at the top

Pop

Input A stack.
Output A new stack with the top element removed.

Signature

stack_pop(a: Stack): Stack

Example

stack_pop(stack_new([1, 2, 3])) // returns a stack with 2 at the top

Peek

Input A stack.
Output The element at the top of the stack.

Signature

stack_peek(a: Stack): Any

Example

stack_peek(stack_new([1, 2, 3])) // returns 3

Reverse

Input A stack.
Output A new stack with the elements in reverse order.

Signature

stack_reverse(a: Stack): Stack

Example

stack_reverse(stack_new([1, 2, 3])) // returns a stack with 1 at the top

Is Empty

Input A stack.
Output True if the stack is empty, false otherwise.

Signature

stack_isEmpty(a: Stack): Boolean

Example

stack_isEmpty(stack_new([])) // returns true

Is Not Empty

Input A stack.
Output True if the stack is not empty, false otherwise.

Signature

stack_isNotEmpty(a: Stack): Boolean

Example

stack_isNotEmpty(stack_new([1, 2])) // returns true

Length

Input A stack.
Output The number of elements in the stack.

Signature

stack_length(a: Stack): Number

Example

stack_length(stack_new([1, 2, 3])) // returns 3