第19989题 单选
将数组奇数放前半部分、偶数放后半部分的C++代码第9行横线处应填入的语句是?
#include <iostream>
using namespace std;

int main() {
 int arr[] = {1, 2, 3, 4, 5};
 int left = 0, right = 4;
 while (left < right) {
  while (arr[left] % 2 == 1 && left < right) left++;
  ————————————————————————————————————————————————
  if (left < right) {
   swap(arr[left], arr[right]);
  }
 }
 for (int i = 0; i < 5; i++) {
  cout << arr[i] << " ";
 }
 return 0;
}
A
while (arr[left] % 2 == 0 && left < right) right--;
B
while (arr[right] % 2 == 0 && left < right) left--;
C
while (arr[right] % 2 != 0 && left < right) right--;
D
while (arr[right] % 2 == 0 && left < right) right--;
提交0次 正确率0.00%
答案解析