Skip to content

Instantly share code, notes, and snippets.

View tjbulick's full-sized avatar
🎯
Focusing

Egor Pishchalnikov tjbulick

🎯
Focusing
View GitHub Profile
@tjbulick
tjbulick / queue-using-two-stacks.js
Created January 17, 2020 08:32
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.)
class Queue {
constructor() {
this.inbox = [];
this.outbox = [];
}
enqueue(item) {
this.inbox.push(item);
}