Write a method named EvenBeforeOdd
that accepts an array of integers as a parameter and rearranges its elements so that all even values appear before all odds.
For example, if the following array is passed to your method:
int[] numbers = {5, 2, 4, 9, 3, 6, 2, 1, 11, 1, 10, 4, 7, 3};
Then after the method has been called, one acceptable ordering of the elements would be:
{4, 2, 4, 10, 2, 6, 3, 1, 11, 1, 9, 5, 7, 3}
The exact order of the elements does not matter, so long as all even values appear before all odd values.
For example, the following would also be an acceptable ordering:
{2, 2, 4, 4, 6, 10, 1, 1, 3, 3, 5, 7, 9, 11}
Do not make any assumptions about the length of the array or the range of values it might contain.
For example, the array might contain no even elements or no odd elements.
You should not use any temporary arrays to help you solve this problem.
(But you may declare as many simple variables as you like, such as int
s.)
You may not use any other data structures such as string
s orList
s.
You should not use the Sort
method in your solution.