Queue Command Processor

Queue Data Structures Simulation

Queue Command Processor

You are provided with a list of commands as strings that simulate operations on a queue.

Commands

  • enqueue X: Adds an integer X to the back of the queue.
  • dequeue: Removes the integer at the front of the queue and outputs it. If the queue is empty, output null.
  • peek: Outputs the integer at the front of the queue without removing it. If the queue is empty, output null.

Process each command in the given order. For enqueue commands, no output is produced. For dequeue and peek commands, append the returned value to your results list.

Example

For commands:

["enqueue 10", "enqueue 20", "peek", "dequeue", "peek", "dequeue", "dequeue"]

The output should be:

[10, 10, 20, null]

Instructions

Implement a function that takes an array (or list) of command strings and returns an array (or list) of outputs corresponding to the dequeue and peek operations.

Happy coding on this fine day!