第21233题 单选题
给定C++实现的二叉树广度优先搜索代码,遍历指定二叉树的可能输出是哪一项?

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

void bfs(TreeNode* root) {
  if (root == NULL) {
    return;
  }
  queue<TreeNode*> q;
  q.push(root);
  while (!q.empty()) {
    TreeNode* current = q.front();
    q.pop();
    cout << current->val << " ";
    if (current->left) {
      q.push(current->left);
    }
    if (current->right) {
      q.push(current->right);
    }
  }
}

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

{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析