/ x / datastructure@1.2.1 / linkedList / singly

Singly Linked List Api

DataType<T> = {
    key: string|number
    value: T

// static method that creates a instance of `SinglyLinkedList` class.

// Time Complexity: O(1)
size: number;

// *generator function, it returens an iterator.
iterator(): Generator

// Time Complexity: O(1)
prepend(data: DataType<any>): boolean;
append(data: DataType<any>): boolean;

// Time Complexity: O(n)
add(data: DataType<any>, position: number): boolean;

// Time Complexity: O(1)
getFromHead(): object|false;

// Time Complexity: O(1)
getFromTail(): object|false;

// Time Complexity: O(n)
log(): void;

// Time Complexity:
// head node: O(1), other nodes: O(n)
remove(key: string|number): object|boolean;

// Time Complexity:
// head & tail node: O(1), other nodes: O(n)
update(key: string|number, newValue: any): object|boolean;

// Time Complexity:
// head node & tail node: O(1), other nodes: O(n)
search(key: string|number): object|boolean


import { SinglyLinkedList } from "";

const singlyLinkedList = SinglyLinkedList.createSL()

// iterator method returns a *generator function
const iterator = singlyLinkedList.iterator()
let iteratorNext =
// console.log(,;
while (iteratorNext.done === false) {
    iteratorNext =

// linked list size

// adding data at the head of linked list
singlyLinkedList.prepend({key: 'a', value: 'apple'})
singlyLinkedList.prepend({key: 'b', value: [1, 2, 3]})
singlyLinkedList.prepend({key: 11, value: 'add to head'})

// adding data at the tail of linked list
singlyLinkedList.append({key: 'c', value: 'add to last'})

// insert anywhere except head & tail
singlyLinkedList.add({key: 'x', value: 'X'}, 1)

// get data from head or tail

// console all values

// remove or delete data from linked list

// update data in linked list
singlyLinkedList.update('a', [1, 4, 8])

// searching data in linked list'Sourav')
Implement different Data Structures using TypeScript. Deno Third-party Module.
GitHub RepositoryAbmSourav/dataStructure
GitHub Stars

Version Info

Tagged at
10 months ago