Single Linked List is dynamical data structure addon to JS that allows you to create linked and linked circular lists.
Note: circular lists is read-only
const Node = require('node-single_linked_list').SingleLinkedList;
let root = new Node(0);
let root2 = new Node(0);
root2.addNode(1);
root2.addNode(0);
root.addNode(15);
root.addNode({'foo':1,'bar':'tender'});
root.getValue(1); //returns '15'
This function always takes last element of the list and set next element link as pointer from parameters:
root.addNext(root); //now list is circular with tail-head connection
Note: if list is circular function will return '-1'
Node.getNextTotal(root); //returns '-1'
This is static function that returns true/false if list circular or not and '-1' if pointer is wrong.
Node.isCircular(root); //returns 'true'
This is static function that returns true/false if list contains palindrome or not and '-1' if pointer is wrong or function is circular.
Node.isPalindrome(root2); //returns 'true'
This is static function that removes duplicates from list (if exist) returns '0' if all ok and '-1' if pointer is wrong or list is circular.
Node.removeDuplicates(root2); //returns '0'
root2.getValue(2); //returns out of border error
npm install node-single_linked_list
npm test
P.S.: for additional info see JSDocs