UNPKG

@figliolia/data-structures

Version:

Efficient data structures for every day programming

42 lines (41 loc) 1.04 kB
declare class ListNode<T> { value: T; previous: ListNode<T> | null; next: ListNode<T> | null; constructor(value: T, previous?: ListNode<T> | null, next?: ListNode<T> | null); } /** * Linked List * * A doubly linked list mimicking the interface of JavaScript arrays * * ```typescript * import { LinkedList } from "@figliolia/data-structures"; * * const list = new LinkedList<number>(); * list.push(1); * list.push(2); * list.push(3); * for(const item of list) { * console.log(item); // 1, 2, 3 * } * list.pop(); // 3 -> O(1) * list.shift() // 1 -> O(1) * list.push(3) // O(1) * list.unshift(1) // O(1) * ``` */ export declare class LinkedList<T> { size: number; head: ListNode<T> | null; tail: ListNode<T> | null; constructor(...items: T[]); push(item: T): number; unshift(item: T): number; shift(): T | undefined; pop(): T | undefined; peekLeft(): T | undefined; peekRight(): T | undefined; [Symbol.iterator](): Generator<T, void, unknown>; } export {};