十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
#include
void show(int *arr, int len)//输出函数
{
int i;
for (i = 0; i < len; i++)
{
printf("%d ", arr[i]);
}
}
void Swap_arr(int *arr, int len)
{
int left = 0;
int right = len - 1;
while (left < right)
{
while (left < right&&arr[left] % 2 == 1)
{
left++;
}
while (left < right&&arr[right] % 2 == 0)
{
right--;
}
if (left < right)
{
int temp;
temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
}
}
show(arr, len);
}
int main()
{
int arr[] = {1,2,3,4,5,6,7,8,9};
int len = sizeof(arr) / sizeof(arr[0]);
Swap_arr(arr, len);
return 0;
}