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

A33222. 阅读以下广度优先搜索的代码: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 (…

单选题 困难

题目描述

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

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);

}

}

}

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

选项(单选)

上一题 下一题