#include <stdio.h>
void move_odd_even(int arr[], int sz)
{
int left = 0;
int right = sz - 1;
while (left < right)
{
while ((left < right) && arr[left] % 2 == 1)//这里left<right是为了避免越界,如果数组中全为奇数则会造成越界
{
left++;
}
while ((left < right) && arr[right] % 2 == 0)
{
right--;
}
if (left < right)
{
int tmp = arr[left];
arr[left] = arr[right];
arr[right] = tmp;
left++;
right--;
}
}
}
int main()
{
int arr[10] = { 0 };
int i = 0;
int sz = sizeof(arr) / sizeof(arr[0]);
for (i = 0;i < sz;i++)
{
scanf_s("%d", &arr[i]);
}
move_odd_even(arr, sz);
for (i = 0;i < sz;i++)
{
printf("%d ", arr[i]);
}
return 0;
}