Options
All
  • Public
  • Public/Protected
  • All
Menu

A LIFO queue, where the last element to be pushed into the queue is the first element to be popped out of it.

import { Stack } from "scl"

Pushing and popping an element are both in O(1).

Property name Worst-case
add() O(1)
peek() O(1)
pop() O(1)
size O(1)
see

Queue

see

PriorityQueue

Type parameters

  • T

    The type of element in this queue.

Hierarchy

Implements

Index

Constructors

constructor

  • new Stack<T>(iterable?: Iterable<T>): Stack<T>
  • Construct a singly-linked list.

    const l = new SingleLinkedList();
    

    You can also constrcut a linked list from any iterable, like so:

    const l = new SingleinkedList([1, 2, 3])
    

    Type parameters

    • T

    Parameters

    • Optional iterable: Iterable<T>

    Returns Stack<T>

Accessors

size

  • get size(): number
  • Count the amount of elements in the collection.

    ⚠️ In most cases, this should be an O(1) operation. However, there are cases where this can be an O(n) operation. Therefore, it is recommended to always cache the result in a local variable.

    Returns number

Methods

[Symbol.iterator]

  • [Symbol.iterator](): IterableIterator<T>
  • Returns an object which is able to sift through the values in this collection.

    The order by which the elements are traversed depends on the kind of collection. For unordered collections, the iteration order is unspecified and may even differ between two iterations on the same collection.

    Returns IterableIterator<T>

add

  • add(element: T): [boolean, SingleLinkedListCursor<T>]

append

  • append(el: T): SingleLinkedListCursor<T>

at

  • at(position: number): SingleLinkedListCursor<T>

clear

  • clear(): void

clone

delete

  • delete(element: T): boolean

deleteAll

  • deleteAll(el: T): number

deleteAt

  • deleteAt(pos: SingleLinkedListCursor<T>): void

first

  • first(): T

getAt

  • getAt(index: number): T

has

  • has(el: T): boolean

insertAfter

  • insertAfter(pos: SingleLinkedListCursor<T>, el: T): SingleLinkedListCursor<T>

insertBefore

  • insertBefore(pos: SingleLinkedListCursor<T>, el: T): SingleLinkedListCursor<T>

last

  • last(): T

peek

  • peek(): T
  • Get the next element in the queue without removing it from the collection.

    Returns T

pop

  • pop(): T
  • Get the next element in the order defined by the queue and remove it from the collection.

    Returns T

prepend

  • prepend(el: T): SingleLinkedListCursor<T>

rest

toRange

  • toRange(): SingleLinkedListRange<T>

Legend

  • Property
  • Method
  • Accessor
  • Property
  • Method
  • Inherited property
  • Inherited method

Generated using TypeDoc