You are given an initial list representing a queue and a list of operations. Each operation is a string either in the format:
enqueue X
(which means add the element X to the end of the queue) ordequeue
(which means remove the element from the front of the queue).Your task is to simulate the operations in the given order and return the final state of the queue.
Given the initial queue: [1, 2, 3]
And the operations: ["enqueue 4", "dequeue", "enqueue 5"]
Execution:
enqueue 4
: Queue becomes [1, 2, 3, 4]
dequeue
: Queue becomes [2, 3, 4]
enqueue 5
: Queue becomes [2, 3, 4, 5]
Output: [2, 3, 4, 5]
dequeue
operation is encountered when the queue is empty, it should be ignored (no operation performed).Good luck and happy coding! (Bonus: Reflect on the evolution of data structures in computing history on this day.)