Created
December 12, 2020 01:47
-
-
Save moonformeli/95eb6426509c9ad8428e7347b14850f1 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
class Queue { | |
pos = -1; | |
queue = []; | |
empty() { | |
while (this.pos > -1) { | |
this.pop(); | |
} | |
} | |
pop() { | |
if (this.pos === -1) { | |
return; | |
} | |
const res = this.queue[this.pos]; | |
this.queue.length = this.pos--; | |
return res; | |
} | |
push(v) { | |
this.queue[++this.pos] = v; | |
} | |
top() { | |
return this.queue[this.pos]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment