Skip to content

SerayaEryn/linkedlist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

linkedlist

Build Status Coverage Status NPM version JavaScript Style Guide

Doubly linked list implementation.

Installation

npm install @serayaeryn/linkedlist

Example

const LinkedList = require('@serayaeryn/linkedlist');

const linkedList = new LinkedList();
linkedList.add('a');
linkedList.add('b');

for (const element of linkedList) {
  console.log(element);
}
linkedList.remove(0);

API

length

Reflects the number of elements in the linked list.

shift()

Removes the first element from the linked list and returns that element.

pop()

Removes the last element from the linked list and returns that element.

unshift(element)

Adds the element to the front of the linked list.

push(element)

Adds the element to the end of the linked list.

add([ index ], element)

Adds the element at the specified index of the linked list. If no index is specified the element will be added at the end of the linked list.

addAll([ index ], elements)

Adds the elements at the specified index of the linked list. If no index is specified the elements will be added at the end of the linked list.

clear()

Removes all elements from the linked list.

get(index)

Returns the element at index.

set(index, element)

Sets the element at the specified index and returns the element

remove(index)

Removes the element at index.

indexOf(element)

Returns the first (least) index of an element within the linked list equal to the specified value, or -1 if none is found.

lastIndexOf(element)

Returns the last (greatest) index of an element within the linked list equal to the specified value, or -1 if none is found.

includes(element)

Determines whether a linked list contains a certain element.

toString()

Returns a string representing the linked list and its elements.

License

MIT

About

a doubly linked list implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published