namastey-singly-linkedlist
v1.0.3
Published
A robust package that implements the Singly Linked List data structure with various essential methods for JavaScript developers.
Downloads
7
Maintainers
Readme
namastey-singly-linked-list
Brief Description
namastey-singly-linked-list
is a JavaScript package that provides an implementation of a Singly Linked List data structure. It includes various important methods to manage and manipulate linked lists.
Features
append(value): Adds a new node with the specified value to the end of the list.
insertAt(value, position): Inserts a new node with the specified value at the given position in the list.
remove(value): Removes the first node with the specified value from the list.
find(value): Searches for a node with the specified value and returns it if found.
printList(): Prints the entire list in a readable format, ending with
null
.getSize(): Returns the number of nodes in the list.
Installation
You can install this package globally using npm:
npm install -g namastey-singly-linked-list
Examples
import SinglyLinkedList from 'namastey-singly-linkedlist';
const list = new SinglyLinkedList();
list.append(10);
list.append(20);
list.append(30);
list.insertAt(15, 1);
list.printList(); // Output: 10 -> 15 -> 20 -> 30 -> null
console.log('Size of list:', list.getSize()); // Output: Size of list: 4
list.remove(20);
list.printList(); // Output: 10 -> 15 -> 30 -> null