Messing with stacks and queues again, this time using two stacks to mimic a queue. The plan is to create a stack structure, then initialize two of them; one to hold the queue as it fills up (using the
push() method, using the
pop() method to get to the the front of the queue (bottom of the stack), remove the first entry, and put all the removed items back.
|3 4 5 6 --> dequeue() --> |4 5 6
2 Stacks 1 Queue
Let’s try and take a different spin on yesterday’s problem. Today’s goal will be to implement a stack. Then using two instances of the stack you’ll want to mimic the functionality of a queue. Thus your queue will have an enqueue and dequeue method but those methods will only use the push and pop functionality of your stacks.