A lightweight single linked list implementation which supports typescript
npm install single-ll


A single linked list implementation which supports typescript.
``sh`
npm install single-linked-list
`ts
import { SingleLinkedList } from 'single-linked-list';
const singleLinkedList1 = new SingleLinkedList
singleLinkedList.push(1);
singleLinkedList.push(2);
singleLinkedList.push(3);
singleLinkedList.push(4);
singleLinkedList.push(5);
console.log(singleLinkedList1.toArray()); // [1, 2, 3, 4, 5]
const singleLinkedList2 = new SingleLinkedList
singleLinkedList1.fromArray([11, 12, 13, 14, 15]);
console.log(singleLinkedList2.toArray()); // [11, 12, 13, 14, 15]
// It's also iterable
for (let key of singleLinkedList2) {
console.log(singleLinkedList2[key]);
}
// Or
console.log([...singleLinkedList1]);
``
| attributes | parameters | description |
| ---------- | -------------------- | -------------------------- |
| head | SingleLinkedListNode | The first node in the list |
| tail | SingleLinkedListNode | The last node in the list |
| length | number | Length of the list |
| function | parameters | return type | description |
| --------- | ----------------------- | ------------------------------------ | -------------------------------------------------- |
| push | value: T | SingleLinkedList
| unshift | value: T | SingleLinkedList
| pop | | SingleLinkedListNode
| shift | | SingleLinkedListNode
| get | index: number | SingleLinkedListNode
| remove | index: number | SingleLinkedListNode
| set | value: T, index: number | boolean | change node value at certain index |
| insert | value: T, index: number | boolean | insert node at certain index |
| toArray | | T[] | return the linked list in the form of normal array |
| fromArray | array: T[] | SingleLinkedList
| reverse | | SingleLinkedList
| clear | | void | remove all nodes |