Queue Reorder Challenge

Queue Data Structures Algorithm

Queue Reorder Challenge

In many real-world applications, tasks and events get enqueued continuously, and sometimes, it is necessary to rearrange the order based on certain criteria. In this challenge, you are given a queue (represented as a list or array) of integers. Your task is to reorder the queue so that all even numbers appear before all odd numbers while preserving the relative order among even and odd numbers.

Problem Statement

Implement a function reorderQueue (or similar name based on your programming language) that takes a queue of integers as input and returns a new queue (or modifies the existing queue) where:

  • All even integers appear at the front of the queue in the order they appeared originally.
  • All odd integers follow, also preserving their original order.

This problem leverages basic queue operations and is a great exercise in understanding how to efficiently manipulate sequences.

Hint: Think of iterating through the original queue, collecting even and odd numbers separately, and then concatenating them.

On November 27, 2024, as we approach the end of the year, take this opportunity to refine your skills in handling basic data structures and operations such as queues.

Function Signature Example

Below is language-agnostic starter code with input/output comments to help you begin your solution.