#10398. szjy_6_树_018
szjy_6_树_018
szjy_6_树_018
阅读代码,程序输出是( )。
#include <iostream>
#include <queue>
using namespace std;
struct Node {
int value;
Node* left = nullptr;
Node* right = nullptr;
};
void print(Node* root) {
queue<Node*> q;
q.push(root);
while (!q.empty()) {
Node* p = q.front();
q.pop();
cout << p->value << ' ';
if (p->left) q.push(p->left);
if (p->right) q.push(p->right);
}
}
int main() {
Node a{8}, b{4}, c{12}, d{2}, e{6}, f{10};
a.left = &b; a.right = &c;
b.left = &d; b.right = &e;
c.left = &f;
print(&a);
}
{{ select(1) }}
2 4 6 8 10 128 4 12 2 6 102 6 4 10 12 88 4 2 6 12 10