Simple implementation of linked list data structure.
To create an instance there are several options.
const LinkedList = require('linked-list');
const emptyList = new LinkedList();
const listWithHeadOnly = new LinkedList(2);
const listWithSeveralNodes = new LinkedList([1,2]);Insert time complexity is constant - O(1). You can insert new value into the list using method add:
list.add(2);
list.add(3);Remove time complexity is linear - O(N). You can remove values using method remove. Return value: index of the removed element.
const list = new LinkedList([1, 2, 3]);
const index = list.remove(2);
console.log(index); // 1To print the list, you can use method print.
const list = new LinkedList([1, 2, 3]);
list.print();Fully covered with tests including edge cases. To run tests use:
npm test