Segregate even and odd numbers in array

Given an array of integer elements, Our goal is to organize the array using even and odd numbers. The order of the resultant array is form of subarrays that contain even and odd numbers. Write a program to segregate array elements. For example.

Example 
arr = [1, 8, 7, 3, 9, 4, 2, 5, 10]

// After segregate
output = [8, 4, 2, 10,  9, 1, 7, 5, 3]

Here even  [8, 4, 2, 10]
     odd   [9, 1, 7, 5, 3]

Note that the resulting even and odd elements order is not significant. But all numbers must be at the beginning of the array and all odd numbers must be at the end of the array.




Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2022, kalkicode.com, All rights reserved