Problem of the Day: Stacks & Queues

One data structure that can do both stack and queue functions. The underlying structure will be a double-linked-list because I haven’t used much of those lately.

Stacks && Queues

Glad you’re back for another great week!

Today’s problem is about combining two common data structures in to one. Your goal is to implement a data structure that can pop and push like a stack and also dequeue and enqueue like a queue. Here is an example of how your data structure should work.

store.push(5)
> [5]

store.enqueue(6)
> [5,6]

store.push(7)
> [7,5,6]

store.pop()
> 7

store.dequeue()
> 5

Note: pop and dequeue will essentially do the same thing since they always pull from the front of the line. As always, bonus points for efficiency!

Stacks & Queues

One thought on “Problem of the Day: Stacks & Queues”

Comments are closed.