• Sorts a linked list using the insertion sort algorithm. The algorithm iterates over the list, and for each node (starting from the second), finds the correct sorted position in the already-sorted portion (to its left) and re-inserts the node there.

    Type Parameters

    • T

    Parameters

    • list: default<T>

      The linked list to sort.

    • predicate: (a: default<T>, b: default<T>) => boolean

      A comparison function that returns true if the first node should come after the second. For example, (a, b) => a.data > b.data will sort numbers in ascending order.

    Returns void

    If the list or predicate is not provided or invalid.