Last active
July 19, 2021 22:22
-
-
Save Mango3403/b09a568ec728e67480d45b50394ae8d2 to your computer and use it in GitHub Desktop.
js-queue-stack
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
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