Implementing Stacks & Queues
What data structure is being simulated using two stacks?
class Stack {
constructor() {
this.stack1 = [];
this.stack2 = [];
}
enqueue(element) {
while (this.stack1.length) {
this.stack2.push(this.stack1.pop());
}
this.stack1.push(element);
while (this.stack2.length) {
this.stack1.push(this.stack2.pop());
}
}
dequeue() {
return this.stack1.pop();
}
}