大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
#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;
}