Queue Operation Simulator

Queue Data Structures Simulation Easy Operations

Queue Operation Simulator

On February 22, a day associated with leadership and order, implement a queue simulator that processes a series of operations. The operations are provided in an array of strings, where each string represents one of the following commands:

  • ENQUEUE x: Add element x to the end of the queue. x will always be a positive integer.
  • DEQUEUE: Remove an element from the front of the queue. If the queue is empty, ignore this operation.
  • PEEK: Output the element at the front of the queue without removing it. If the queue is empty, output null (or equivalent in your language).

You will also be provided with an integer representing the maximum capacity of the queue. If an ENQUEUE operation is attempted when the queue is at full capacity, ignore that operation.

Your task is to implement the function processQueueOperations(operations, capacity) which processes the operations and returns an object containing the final state of the queue and an array of results recorded from the PEEK commands in the order they were encountered.

Example

Input:

operations = ["ENQUEUE 10", "ENQUEUE 20", "PEEK", "DEQUEUE", "PEEK", "ENQUEUE 30"], capacity = 3

Output:

{
  "queue": [20, 30],
  "peekResults": [10, 20]
}

Implement the solution ensuring that all operations are handled according to the description.