以下代码的功能是将数组中的奇数和偶数分别放在数组的前半部分和后半部分,横线处应该填入的是()
1 #include <iostream> 2 using namespace std; 3 4 int main() { 5 int arr[] = {1, 2, 3, 4, 5}; 6 int left = 0, right = 4; 7 while (left < right) { 8 while (arr[left] % 2 == 1 && left < right) left++; 9 ———————————————————————————————————————————————————— 10 if (left < right) { 11 swap(arr[left], arr[right]); 12 } 13 } 14 for (int i = 0; i < 5; i++) { 15 cout << arr[i] << " "; 16 } 17 return 0; 18 }
while (arr[left] % 2 == 0 && left < right) right--;
while (arr[right] % 2 == 0 && left < right) left--;
while (arr[right] % 2 != 0 && left < right) right--;
while (arr[right] % 2 == 0 && left < right) right--;