#K62487. Sort Even Before Odd
Sort Even Before Odd
Sort Even Before Odd
You are given a list of integers. Your task is to arrange the list such that all even numbers appear before all odd numbers, while preserving the relative order of the even numbers and the odd numbers.
In other words, if the input list contains even numbers and odd numbers, all the even numbers should be moved to the front and the odd numbers to the back without altering the order in which they appear in their respective groups.
Example:
Input: 4 1 3 2 5 Output: 4 2 1 3 5
The solution should read from standard input and print the result to standard output.
inputFormat
The input is given as a single line of space-separated integers. There is no explicit count at the beginning. The integers may be positive, negative, or zero.
outputFormat
Output the rearranged list of integers, with all even numbers appearing before odd numbers, separated by a single space. There should be no trailing spaces.
## sample4 1 3 2 5
4 2 1 3 5