Skip to content

Commit 997ec33

Browse files
committed
refactor: use LinkedList
Since the code is only adding elements to the end of the list and removing elements from the start of the list, that can be handled using a simple linked list.
1 parent 6b665aa commit 997ec33

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/create.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ class Node {
66
}
77
}
88

9-
class DoublyLinkedList {
9+
class LinkedList {
1010
enqueue (data) {
1111
const node = new Node(data)
1212
if (!this.head) {
1313
this.head = node
1414
this.tail = node
1515
} else {
16-
node.prev = this.tail
1716
this.tail.next = node
1817
this.tail = node
1918
}
@@ -23,14 +22,13 @@ class DoublyLinkedList {
2322
if (!this.head) return
2423
const data = this.head.data
2524
this.head = this.head.next
26-
if (this.head) this.head.prev = undefined
27-
else this.tail = undefined
25+
if (!this.head) this.tail = undefined
2826
return data
2927
}
3028
}
3129

3230
module.exports = (slots = 1) => {
33-
const queue = new DoublyLinkedList()
31+
const queue = new LinkedList()
3432

3533
const release = () => {
3634
++slots

0 commit comments

Comments
 (0)