(javascript) fix dequeue exception
This commit is contained in:
parent
31b0908077
commit
d6f9ef665d
@ -34,18 +34,18 @@ class CircularQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dequeue() {
|
dequeue() {
|
||||||
|
if(this.head == null) return -1
|
||||||
|
|
||||||
if (this.head === this.tail) {
|
if (this.head === this.tail) {
|
||||||
const value = this.head.element
|
const value = this.head.element
|
||||||
this.head = null
|
this.head = null
|
||||||
return value
|
return value
|
||||||
} else if (this.head !== null) {
|
} else {
|
||||||
const value = this.head.element
|
const value = this.head.element
|
||||||
this.head = this.head.next
|
this.head = this.head.next
|
||||||
this.tail.next = this.head
|
this.tail.next = this.head
|
||||||
return value
|
return value
|
||||||
} else {
|
}
|
||||||
return -1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
display() {
|
display() {
|
||||||
|
Loading…
Reference in New Issue
Block a user