#10424. szjy_6_树_044
szjy_6_树_044
szjy_6_树_044
阅读代码,程序输出是( )。
#include <iostream>
using namespace std;
struct Node {
int value;
Node* left = nullptr;
Node* right = nullptr;
};
void printLeaf(Node* root) {
if (root == nullptr) return;
if (root->left == nullptr && root->right == nullptr) {
cout << root->value << ' ';
return;
}
printLeaf(root->left);
printLeaf(root->right);
}
int main() {
Node a{1}, b{2}, c{3}, d{4}, e{5}, f{6};
a.left = &b; a.right = &c;
b.left = &d; b.right = &e;
c.left = &f;
printLeaf(&a);
}
{{ select(1) }}
1 2 32 3 4 5 66 5 44 5 6