using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
Random random = new Random();
int[] arr = new int[10];
for (int i = 0; i < arr.Length; ++i)
{
arr[i] = random.Next(100);
}
PrintArray(arr);
Console.WriteLine();
Method(arr);
PrintArray(arr);
}
static void PrintArray(int[] arr)
{
if (arr != null && arr.Length != 0)
{
foreach (int item in arr)
{
Console.WriteLine(item);
}
}
}
static int[] Method(int[] arr)
{
if (arr != null && arr.Length != 0)
{
int temp = 0;
int left = 0;
int right = arr.Length - 1;
while (left < right)
{
if (!IsEven(arr[left]) && !IsEven(arr[right]))
{
left++;
}
else if (!IsEven(arr[left]) && IsEven(arr[right]))
{
left++;
right--;
}
else if (IsEven(arr[left]) && !IsEven(arr[right]))
{
temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
left++;
right--;
}
else
{
right--;
}
}
}
return arr;
}
static bool IsEven(int a)
{
return (a & 1) == 0;
}
}
}