LinkedStack

Container of elements that are inserted and removed according to the LIFO principle. This structure is based on SinglyLinkedList.

new LinkedStack()

/**
 * Creates an instance of LinkedStack.
 *
 * @param elements List of elements to create the new stack with.
 */
constructor(elements: T[] = [])

length

length: number

Number of elements in the stack. This field is read only.

Examples:

import { LinkedStack } from 'ads-js/queues';

const stack = new LinkedStack();

stack.length === 0; // true
stack.push(1);
stack.length === 1; // true

clear()

isEmpty()

Running time O(1)

Checks whether the stack is empty or not.

Returns:

TRUE if the stack is empty, FALSE otherwise.

Examples:

pop()

push()

top()

Last updated

Was this helpful?