Install
via npm
npm install ds-sll
via git
git clone https://github.com/scriptnull/ds-sll.git
Usage
var ds = LinkedList = dsLinkedList Node = dsNode ;
Node
Nodes are elementary blocks of Linked List. To maintain data within Linked List, use Node objects as containers. Nodes have data and a pointer to next node.
Creating a node
var numberNode = 1;var stringNode = 'yo';var objectNode = foo : 'bar';
Properties
var node = 1;console; //1 - data of nodeconsole; //null - next pointer
Methods
- setNext(node)
- getNext()
Linked List
Singly Linked Lists are collection of Node objects having only next pointer.
Creating a Linked List
var ll = ;
Properties
var ll = ;console; // 0 - length of linked listconsole; // null - head of the linked list
Methods
- insertAtHead(node)
- insertAtTail(node)
- insertAtPosition(node,position)
- deleteAtHead()
- deleteAtTail()
- deleteAtPosition(position)
- getDataAtPosition(position)
- findPositionByData(data)
Contributing
Any kind of contribution is welcomed. If you are adding new features , be sure to write the required tests for it.
Tests
Tests are written with Mocha + inbuilt Node.js assert library. Initail commit has about 30+ tests. If you feel ds-sll is going wrong somewhere. You could report it in issues or better submit a pull request by describing the case in a test suite. You can track the build status from travis-ci