Stack

DataStructure. Stack

A stack is similar to lists in that they have an order, but they are limited to only pushing and popping values at the end of the stack.

Constructor

new Stack()

Start with an empty array and store the length of the "list". Note that we to store the length separately because the "memory" doesn't have a length that can be read.
Source:

Methods

peek() → {*}

Retrieve the item at the top of the stack without removing it from the stack
Source:
Returns:
Type
*

pop() → {*}

Pop items off of the end of our list. Similar to push all we need to do is remove the value at the address at the end of our list. Then just decrement length.
Source:
Returns:
Type
*

push(value)

Add an item to the end of the list. Adding a value after the end of our list. Just add the value and increment the length.
Parameters:
Name Type Description
value * Value that should be added to the list
Source: