Skip to content

Utilities: NT lists

Eugene Lazutkin edited this page Mar 10, 2026 · 5 revisions

Utilities for inspecting null-terminated (NT) lists and converting between NT and circular formats. Works with both DLL and SLL.

Legend for tables
  • API
    • options - an optional options object, which contains nextName and prevName link names with default values "next" and "prev".
      • Only doubly linked lists use prevName.
    • head - the first node object of the list
    • node - a node object in the list
    • list - a returned object with two properties: head and tail. head is the first node of the list and tail is the last one.
  • Complexity
    • O - complexity of an operation
    • O(1) - constant time
    • O(n) - linear time proportional to the list size
    • O(k) - linear time proportional to the list/range argument size

Functions for null-terminated lists.

import {makeSListFromNTList} from 'list-toolkit/nt-utils.js';

Exported functions:

Function Return Value Description O
isNTList(head, options) boolean Check if the list is an NT list. O(n)
getNTListTail(head, options) node Get the last node of the NT list. O(n)
getNTListHead(node, options) node Get the first node of the NT doubly linked list. O(n)
getNTListLength(head, options) number Get the length of the NT list. O(n)
makeListFromNTList(node, options) list Convert the NT list to a doubly linked list. O(n)
makeSListFromNTList(head, options) list Convert the NT list to a singly linked list. O(n)
makeNTListFromList(head, options) list Convert the DLL list to an NT list. O(1)
makeNTListFromSListFast(head, options) list Convert the SLL list to a NT singly linked list. O(1)
makeNTListFromSList(head, options) list Convert the SLL list to a NT singly linked list. O(n)

isNTList() returns true if following next links reaches null; returns false if the traversal loops back (circular list). Works with DLL and SLL.

getNTListTail() follows next links to the last node. getNTListHead() follows prev links to the first node (DLL only). getNTListLength() counts nodes.

All makeXXX() functions modify nodes in place and return {head, tail}.

makeXXXFromNTList() functions produce headless circular lists usable by ExtList / ExtSList, or convertible to hosted lists via List.fromExtList() / SList.fromExtList().

makeNTListFromXXX() functions convert headless circular lists to NT lists. They do not detach nodes from hosted lists — use releaseNTList() for that.

makeNTListFromSListFast() is O(1) but rotates the list: the original head becomes the tail. makeNTListFromSList() preserves order in O(n).

Clone this wiki locally