Created
February 23, 2020 12:19
-
-
Save claeusdev/83410778b0d093d9d4fdd58d760c6a0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Queue.prototype.enqueue = function(value){ | |
if(this.size < this.capacity){ | |
this.storage[this.tail++] = value | |
return this.size | |
} | |
return "Max capacity reached, remove one before you can add another." | |
} | |
Queue.prototype.dequeue = function(){ | |
// get item from front of queue | |
// remove item from front | |
// if item at the fron is less than item at last increase item at head | |
// return item | |
const item = this.storage[this.head] | |
delete this.storage[this.head] | |
if(this.head < this.tail) this.head++; | |
return this.item | |
} | |
Queue.prototype.peek = function(){ | |
// return item next in line to be removed | |
return this.storage[this.head] | |
} | |
Queue.prototype.size = function(){ | |
// returns size of Queue | |
return this.tail - this.head | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment