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): StackExample
stack_new([1, 2, 3]) // returns a stack with 3 at the topPush
| Input | A stack and an element. |
|---|---|
| Output | A new stack with the element added to the top. |
Signature
stack_push(a: Stack, b: Any): StackExample
stack_push(stack_new([1, 2]), 3) // returns a stack with 3 at the topPop
| Input | A stack. |
|---|---|
| Output | A new stack with the top element removed. |
Signature
stack_pop(a: Stack): StackExample
stack_pop(stack_new([1, 2, 3])) // returns a stack with 2 at the topPeek
| Input | A stack. |
|---|---|
| Output | The element at the top of the stack. |
Signature
stack_peek(a: Stack): AnyExample
stack_peek(stack_new([1, 2, 3])) // returns 3Reverse
| Input | A stack. |
|---|---|
| Output | A new stack with the elements in reverse order. |
Signature
stack_reverse(a: Stack): StackExample
stack_reverse(stack_new([1, 2, 3])) // returns a stack with 1 at the topIs Empty
| Input | A stack. |
|---|---|
| Output | True if the stack is empty, false otherwise. |
Signature
stack_isEmpty(a: Stack): BooleanExample
stack_isEmpty(stack_new([])) // returns trueIs Not Empty
| Input | A stack. |
|---|---|
| Output | True if the stack is not empty, false otherwise. |
Signature
stack_isNotEmpty(a: Stack): BooleanExample
stack_isNotEmpty(stack_new([1, 2])) // returns trueLength
| Input | A stack. |
|---|---|
| Output | The number of elements in the stack. |
Signature
stack_length(a: Stack): NumberExample
stack_length(stack_new([1, 2, 3])) // returns 3