Print Linked List
Pretty print for singly linked lists with loop detection
A → B → C → D → E → [null]
Install
npm i print-linked-list
Usage
I used that module when studying Linked Lists exercises.
By default it utilizes console.log
with colored output to show a list structure (see available options below).
Basic usage:
const printLinkedList = ; const list = 'A';list;list;list;list; ;
Output:
A → B → C → D → E → [null]
It also has a loop detection. Example:
const printLinkedList = ; const list = 'A';list;list;list;listnextnextnextnext = listnextnext; // making a loop ;
Output will be:
A → B ⤇ C → D ⤇ [loop]
The double arrow point on loop entry node.
Options:
nextName
{String} Key name for next node prop. Default = "next"valueName
{String} Key name for value prop. Default = "value"output
{String} Result output method ("console" or "return"). Default = "console"colors
{Boolean} Use colors in console output. Default = true