small-linked-list

0.1.0 • Public • Published

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

Package Sidebar

Install

npm i small-linked-list

Weekly Downloads

3

Version

0.1.0

License

MIT

Unpacked Size

10 kB

Total Files

10

Last publish

Collaborators

  • pengfeizheng