simple-linked-list
v1.0.5
Published
Zero dependency - Simple linked list implementation with typescript support
Downloads
4
Readme
Simple linked list implementation with typescript support
- types included
| Statements | Functions | Lines | | ------------------------- | ------------------------ | -------------------- | | | | |
API
const list = new LinkedList<number>();
list.isEmpty(); // true
list.push(3); // return list size
list.push(5);
list.toString(); // 3,5 works only with primitives
list.insert(4, 1); // insert(node, index): boolean
list.get(1); // 4
list.remove(1); // 4
list.indexOf(3); // 0
list.constains(3); // true
list.getSize(); // 2
for (const val of list.traverse()) {
console.log(val);
} // 3,5
list.reset(); // true
All API methods support type definition
interface User {
name: string;
}
const john: User = { name: "john" };
const gregory: User = { name: "gregory" };
const list = new LinkedList<User>();
list.push(john);
list.push(gregory);
for (const value of list.traverse()) {
console.log(value);
} // { name: 'john' }, { name: 'gregory' }