parrot-sll
v1.0.1
Published
Singly Linked List
Downloads
6
Maintainers
Readme
parrot-sll
A singly linked list in JavaScript.
Usage
const ParrotSll = require("parrot-sll");
const addressList = ParrotSll();
addressList.add({ name: 'Bruce Lee', street: 'Kung Fu Street 12' });
addressList.add({ name: 'John Snow', street: 'Winterfell 1' });
console.log(addressList.size()) // "2"
console.log(addressList.get(0).name) // "Bruce Lee"
console.log(addressList.get(1).name) // "John Snow"
addressList.remove(0);
console.log(addressList.size()) // "1"
console.log(addressList.get(0).name) // "John Snow"Please note that
Methods
add(object: any): voidAdds an object to the listsize(): numberReturns the size of the listget(index: integer): anyReturns object at given index. If index is out of bounds it returns null.remove(index: integer): anyRemoves the object at given index from the list and returns the removed object. If the index is out of bounds it returns null.
Runtime complexity
add: O(1)size: O(1)get: O(n)remove: O(n)
