Skip to content

Instantly share code, notes, and snippets.

@moonformeli
Created December 12, 2020 01:47
Show Gist options
  • Save moonformeli/95eb6426509c9ad8428e7347b14850f1 to your computer and use it in GitHub Desktop.
Save moonformeli/95eb6426509c9ad8428e7347b14850f1 to your computer and use it in GitHub Desktop.
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