Skip to content

Instantly share code, notes, and snippets.

@Mango3403
Last active July 19, 2021 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mango3403/b09a568ec728e67480d45b50394ae8d2 to your computer and use it in GitHub Desktop.
Save Mango3403/b09a568ec728e67480d45b50394ae8d2 to your computer and use it in GitHub Desktop.
js-queue-stack
function Queue<T>() {
let data: Record<string, T> = {}
let head = 0
let tail = 0
this.enqueue = function(item: T): void {
data[tail] = item;
tail++;
}
this.dequeue = function(): T {
let item = data[head];
delete data[head];
head++;
return item
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment