0.1.0 • Published 5 years ago

small-linked-list v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

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

NameParametersDescription
appendelement:anyAppend 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
indexOfelement:anyFind the corresponding index based on the incoming elment
removeelement:anyRemove an element from the element

LICENSE

MIT @ Zheng peng fei