Segregate Even and Odd numbers
Submissions: 8082   Accuracy:

38.46%

  Difficulty: Basic   Marks: 1

Given an array A[], 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.

Input:
The first line of input contains an integer T, denoting the number of test cases. For each testcase there will be two lines of input: The first line contains a single integer N denoting the size of array.
The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array.

Output:
For each testcase, print the segregated array.

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 105
0 ≤A[i]<=105

Example:
Input:
2
7
12 34 45 9 8 90 3
5
0 1 2 3 4
Output:
8 12 34 90 3 9 45
0 2 4 1 3

** For More Input/Output Examples Use 'Expected Output' option **

Author: vaibhav95


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.