P15200 [GeeksforGeeks] Segregate even and odd numbers4629
普及-
题目描述

Given an array Arr[], write a program that segregates even and odd numbers. The program should put all even numbers first in sorted order, and then odd numbers in sorted order.
Note :- You don't have to return the array, you just have to modify it in-place.
Example 1:
Input:
N = 7
Arr[] = {12, 34, 45, 9, 8, 90, 3}
Output: 8 12 34 90 3 9 45
Explanation: Even numbers are 12, 34,
8 and 90. Rest are odd numbers. After
sorting even numbers 8 12 34 90 and
after sorting odd numbers 3 9 45. Then
concat both.
Example 2:
Input:
N = 5
Arr[] = {0, 1, 2, 3, 4}
Output: 0 2 4 1 3
Explanation: 0 2 4 are even and 1 3
are odd numbers.
Your Task:
You don't need to read input or print anything. Your task is to complete the function segregateEvenOdd() which takes the array of integers arr[] and n as parameters and returns void. You need to modify the array itself.
Expected Time Complexity: O(N log(N))
Expected Auxiliary Space: O(N)
Constraints:
1 ≤ N ≤ 10^{5}
0 ≤ Arr[i] <=10^{5}

输入格式

见题面

输出格式

见题面

样例输入
N = 7 Arr[] = {12, 34, 45, 9, 8, 90, 3}
样例输出
8 12 34 90 3 9 45