Stack
Class | Source Code
implements IStack
Implementation of a stack, a FILO (first in, last out) data structure.
Constructors
Section titled “Constructors”new Stack()
Section titled “new Stack()”Accessors
Section titled “Accessors”isEmpty: boolean
Section titled “isEmpty: boolean”Whether the stack is empty.
length: number
Section titled “length: number”The number of items in the stack.
Methods
Section titled “Methods”clear(): void
Section titled “clear(): void”Clears the stack entirely.
peek(): undefined | T
Section titled “peek(): undefined | T”Shows you the first item in the stack without removing it.
Returns
Section titled “Returns”The first item in the stack, or undefined if the stack is empty.
pop(): undefined | T
Section titled “pop(): undefined | T”Pops the first item on the stack off. This mutates the stack.
Returns
Section titled “Returns”The popped item, or undefined if the stack is empty.
push(item: T): void
Section titled “push(item: T): void”Pushes an item onto the stack, making that item the first one in the stack.
toArray(): T[]
Section titled “toArray(): T[]”Returns
Section titled “Returns”The stack as an array.
toString(): string
Section titled “toString(): string”Returns
Section titled “Returns”The stack as a human-readable string.