dastal
Version:
Data Structures & Algorithms implementations
43 lines (42 loc) • 1.69 kB
TypeScript
import { CompareFn } from '..';
import { LinkedNode } from './linkedNode';
/**
* Sorts a list in place.
*
* Works on complete lists as well as sublists and circular lists:
* - Linked lists will keep the link to the next node beyond the sorted section
* - Doubly linked lists will keep links to the prev and next nodes outside the sorted section
*
* @param node - The head of the list
* @param len - The length of the list beginning from node
* @param isDoubly - Whether node is a doubly linked node
* @param compareFn - A function used to determine the order of elements.
*
* It is expected to return:
* - A negative value if first argument < second argument
* - Zero if first argument == second argument
* - A positive value if first argument > second argument
*
* @returns The new head and tail of the sorted list
*
* @internal
*/
export declare function linkedMergeSort<T, Node extends LinkedNode<T>>(node: Node, len: number, isDoubly: boolean, compareFn: CompareFn<T>): [Node, Node];
/**
* Merges two sorted lists.
*
* @param nodes - The heads of the lists
* @param lens - The lengths of the lists
* @param isDoubly - Whether the lists are a doubly linked
* @param compareFn - A function used to determine the order of elements.
*
* It is expected to return:
* - A negative value if first argument < second argument
* - Zero if first argument == second argument
* - A positive value if first argument > second argument
*
* @returns The new head of the sorted list
*
* @internal
*/
export declare function linkedMergeSorted<T, Node extends LinkedNode<T>>(heads: [Node, Node], lens: [number, number], isDoubly: boolean, compareFn: CompareFn<T>): Node;