C# 实现 奇数偶数排序,奇数在前,偶数在后
public static void SortByOddAndEven(int []arr)
{
for (int i = 0; i < arr.Length; i++)
{
for (int j = arr.Length - 1; j >= i; j--)
{
if (arr[i] % 2 == 0 && arr[j] % 2 != 0)
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
foreach (var a in arr)
{
Console.WriteLine(a);
}
}
static void Main(string[] args)
{
int[] arr = { 23, 2, 32, 89, 3, 45, 6, 8, 34, 66, 75, 45, 57, 573, 564, 4556,4579 };
SortByOddAndEven(arr);
Console.ReadLine();
}