测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A66844. 阅读以下广度优先搜索的代码:1 void bfs(TreeNode* root) {

单选题

题目描述

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

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 }

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

选项(单选)