small-linked-list

Method library for manipulating linked list data structures.

Usage no npm install needed!

<script type="module">
  import smallLinkedList from 'https://cdn.skypack.dev/small-linked-list';
</script>

README

small-linked-list

A simple linked list.

installation

npm i small-linked-list

Usage

const LinkedList = require('small-linked-list').default;

const test = new LinkedList.default();
test.append('lang').append('demo').append('key');
console.log(JSON.stringify(test.getHead()));
test.insert(2,"test");
console.log(JSON.stringify(test.getHead()));
test.removeAt(2);
console.log(JSON.stringify(test.getHead()));
test.append("element");
console.log(JSON.stringify(test.getHead()));
console.log(JSON.stringify(test.size()));
console.log(JSON.stringify(test.isEmpty()));
console.log(JSON.stringify(test.remove("element")))
console.log(test.indexOf("key"));
console.log(JSON.stringify(test.getHead()));

// {"next":{"next":{"next":null,"element":"key"},"element":"demo"},"element":"lang"}
// {"next":{"next":{"next":{"next":null,"element":"key"},"element":"test"},"element":"demo"},"element":"lang"}
// {"next":{"next":{"next":null,"element":"key"},"element":"demo"},"element":"lang"}
// {"next":{"next":{"next":{"next":null,"element":"element"},"element":"key"},"element":"demo"},"element":"lang"}
// 4
// false
// "key"
// -1
// {"next":{"next":{"next":null,"element":"element"},"element":"demo"},"element":"lang"}

API

Name Parameters Description
append element:any Append elements to the linked list of instances
insert (position:number,element:any) Specify a position of the insertion element
removeAt (position:number) Remove an element from the specified location
isEmpty - Determine if the linked list is empty
size - Get the size of the linked list
indexOf element:any Find the corresponding index based on the incoming elment
remove element:any Remove an element from the element

LICENSE

MIT @ Zheng peng fei