题库 C++/C语言题库 题目列表 阅读以下广度优先搜索的代码:1 void bfs(T...
单选题

阅读以下广度优先搜索的代码:

1 void bfs(TreeNode* root) {
2  if (root == NULL) {
3   return;
4  }
5  queue<TreeNode*> q;
6  q.push(root);
7  while (!q.empty()) {
8   TreeNode* current = q.front();
9   q.pop();
10   cout << current->val << " ";
11   if (current->left) {
12    q.push(current->left);
13   }
14   if (current->right) {
15    q.push(current->right);
16   }
17  }
18 }

使用以上算法遍历以下这棵树,可能的输出是( )。

A.

1 2 8 9 4 5 3 6 7 10 11

B.

1 2 3 4 5 6 7 8 9 10 11

C.

1 2 3 8 9 6 4 5 7 10 11

D.

1 2 3 8 9 4 5 6 7 10 11

题目信息
C++语言等级考试真题 2024年 六级 选择题
0%
正确率
0
评论
46
点击