Skip to content

Instantly share code, notes, and snippets.

Avatar
🙂
Love Open Source!

Egor Pishchalnikov tjbulick

🙂
Love Open Source!
View GitHub Profile
@tjbulick
tjbulick / queue-using-two-stacks.js
Created Jan 17, 2020
Implementation of Queue data structure using two stacks in JavaScript. Actually, it uses two arrays here(because there is no stack in JavaScript), but you should have a look at your language docs: perhaps it provides embedded stack data structure. (For example: Java provides class "Stack", C# similarly, etc.)
View queue-using-two-stacks.js
class Queue {
constructor() {
this.inbox = [];
this.outbox = [];
}
enqueue(item) {
this.inbox.push(item);
}
You can’t perform that action at this time.