Skip to content

Instantly share code, notes, and snippets.

@osha7
Created February 28, 2021 01:00
Show Gist options
  • Save osha7/cbc0c2fc46bb05d5dbddc9c1566a77a4 to your computer and use it in GitHub Desktop.
Save osha7/cbc0c2fc46bb05d5dbddc9c1566a77a4 to your computer and use it in GitHub Desktop.
class Queue {
constructor() {
this.data = {}
this.head = 0
this.tail = 0
}
enqueue(element) {
this.data[this.tail] = element
this.tail++
}
dequeue() {
let removed = this.data[this.head]
delete this.data[this.head]
this.head++
return removed
}
peek() {
return this.data[this.tail]
}
isEmpty() {
return ((this.head - this.tail) === 0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment