Skip to content

lazyexpert/linked-list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

linked-list

Simple implementation of linked list data structure.

Documentation

To create an instance there are several options.

const LinkedList = require('linked-list');

const emptyList = new LinkedList();
const listWithHeadOnly = new LinkedList(2);
const listWithSeveralNodes = new LinkedList([1,2]);

Add

Insert time complexity is constant - O(1). You can insert new value into the list using method add:

list.add(2);
list.add(3);

Remove

Remove time complexity is linear - O(N). You can remove values using method remove. Return value: index of the removed element.

const list = new LinkedList([1, 2, 3]);

const index = list.remove(2);

console.log(index); // 1

Print

To print the list, you can use method print.

const list = new LinkedList([1, 2, 3]);
list.print();

Tests

Fully covered with tests including edge cases. To run tests use:

npm test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published