题库 C++/C语言题库 题目列表 以下代码的功能是将数组中的奇数和偶数分别放在数组的...
单选题

以下代码的功能是将数组中的奇数和偶数分别放在数组的前半部分和后半部分,横线处应该填入的是()

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 }

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--;
题目信息
2025年 三级 选择题
-
正确率
0
评论
35
点击