UNPKG

es-next-tools

Version:

A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.

66 lines (65 loc) 2.14 kB
/** * Represents a node in a linked list. * @template T The type of value stored in the node. */ export declare class Node<T> { value: T; next: Node<T> | null; /** * Creates a new node. * @param {T} value - The value to be stored in the node. */ constructor(value: T); } /** * Represents a singly linked list. * @template T The type of elements in the linked list. * @example * const list = new LinkedList<number>(); * list.append(1).append(2); * console.log(list.toArray()); // [1, 2] */ export declare class LinkedList<T> { head: Node<T> | null; /** * Appends a value to the end of the linked list. * @param {T} value - The value to append. * @returns {LinkedList<T>} The linked list instance for chaining. */ append(value: T): this; /** * Checks if the linked list contains a specific value. * @param {T} value - The value to check for. * @returns {boolean} True if the value is in the linked list, false otherwise. */ contains(value: T): boolean; /** * Removes a value from the linked list. * @param {T} value - The value to remove. * @returns {boolean} True if the value was removed, false otherwise. */ remove(value: T): boolean; /** * Inserts a value at a specific index in the linked list. * @param {T} value - The value to insert. * @param {number} index - The index at which to insert the value. * @returns {LinkedList<T>} The linked list instance for chaining. */ insertAt(value: T, index: number): this; /** * Serializes the linked list to a JSON string. * @returns {string} The serialized linked list. */ serialize(): string; /** * Deserializes a JSON string to populate the linked list. * @param {string} data - The JSON string to deserialize. */ deserialize(data: string): void; /** * Searches for a value in the linked list and returns its index. * @param {T} value - The value to search for. * @returns {number} The index of the value, or -1 if not found. */ search(value: T): number; }