Skip to content

Commit d6f9ef6

Browse files
committed
(javascript) fix dequeue exception
1 parent 31b0908 commit d6f9ef6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

javascript/09_queue/CircularQueueBasedOnLinkedList.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ class CircularQueue {
3434
}
3535

3636
dequeue() {
37+
if(this.head == null) return -1
38+
3739
if (this.head === this.tail) {
3840
const value = this.head.element
3941
this.head = null
4042
return value
41-
} else if (this.head !== null) {
43+
} else {
4244
const value = this.head.element
4345
this.head = this.head.next
4446
this.tail.next = this.head
4547
return value
46-
} else {
47-
return -1
48-
}
48+
}
4949
}
5050

5151
display() {

0 commit comments

Comments
 (0)