Queue Operation Simulator

Queue Simulation Data Structures Operations

Queue Operation Simulator

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) or
  • dequeue (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.

Input

  • An array/list of integers representing the initial state of the queue (front is at index 0).
  • An array/list of strings where each string represents an operation.

Output

  • Return the queue (as an array or list) after performing all operations in order.

Example

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]

Notes

  • If a dequeue operation is encountered when the queue is empty, it should be ignored (no operation performed).
  • You can assume the queue contains integers and the enqueued items will be valid integers.

Good luck and happy coding! (Bonus: Reflect on the evolution of data structures in computing history on this day.)