(javascript) fix dequeue exception

This commit is contained in:
zjhiphop 2019-08-05 17:25:11 +08:00
parent 31b0908077
commit d6f9ef665d

View File

@ -34,17 +34,17 @@ class CircularQueue {
}
dequeue() {
if(this.head == null) return -1
if (this.head === this.tail) {
const value = this.head.element
this.head = null
return value
} else if (this.head !== null) {
} else {
const value = this.head.element
this.head = this.head.next
this.tail.next = this.head
return value
} else {
return -1
}
}