Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kazu69/doubly-linked-list
Doubly Linked List Structure for JavaScript
https://github.com/kazu69/doubly-linked-list
Last synced: 19 days ago
JSON representation
Doubly Linked List Structure for JavaScript
- Host: GitHub
- URL: https://github.com/kazu69/doubly-linked-list
- Owner: kazu69
- Created: 2018-02-12T09:42:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-08-10T17:40:51.000Z (about 3 years ago)
- Last Synced: 2023-03-23T22:15:09.819Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
## doubly-linked-list
> Doubly Linked List Structure Object for JavaScript
### Advantages
- Element addition and deletion processing is fast.
### Disadvantages
- In the case of finding a specific element, it searches all elements and is slow.
### Usage
```sh
npm i kazu69/doubly-linked-list#master
```### property
- head
- tail
- count### method
- length()
- find(value)
- push(value)
- unshift(value)
- pop()
- shift()
- remove(index)
- append(value, index)
- map(callback)
- drop()
- asArray()
- isEmpty()### example
```js
const LinkedList = require('../dist/index.js').default
const list = new LinkedList()list.push(1)
list.push(2)
list.push(3)console.log(list.length()) // => 3
list.unshift(0)
list.unshift(-1)
list.unshift(-2)console.log(list.length()) // => 6
console.log(list.asArray()) // => [-2 ,-1, 0, 1, 2, 3]list.remove(1)
console.log(list.asArray()) // => [ -2, 0, 1, 2, 3 ]list.append(-1, 0)
console.log(list.asArray()) // => [ -1, -2, 0, 1, 2, 3 ]list.pop()
list.pop()
list.pop()
console.log(list.asArray()) // => [ -1, -2, 0 ]
// [-2 ,-1, 0]list.shift()
console.log(list.asArray()) // => [ -2, 0 ]result = list.map(function(node) { node.value = node.value + 1})
console.log(result) // => [ -1, 1 ]console.log(list.head) // => -1
console.log(list.tail) // => 1
console.log(list.isEmpty()) // => falselist.drop()
console.log(list.isEmpty()) // => true
```### Bench spec
See and Execute `bench.js` file.
```sh
node exmaple/bench.jsqueue unshift is 4951 ms
queue shift is 7046 ms
============
linked-list queue unshift is 23 ms
linked-list queue shift is 23 ms
============
stack push is 18 ms
stack shift is 7357 ms
============
linked-list stack push is 26 ms
linked-list stack shift is 6 ms
```### Todo
- [ ] Add Unit Tests
### License
MIT © kazu69