#10388. szjy_6_树_008

szjy_6_树_008

szjy_6_树_008

阅读代码,程序输出是( )。

#include <iostream>
using namespace std;

struct Node {
int value;
Node* left = nullptr;
Node* right = nullptr;
};

void print(Node* root) {
if (root == nullptr) return;
print(root->left);
cout << root->value << ' ';
print(root->right);
}

int main() {
Node a{4}, b{2}, c{7}, d{1}, e{3}, f{6};
a.left = &b;  a.right = &c;
b.left = &d;  b.right = &e;
c.left = &f;
print(&a);
}

{{ select(1) }}

  • 4 2 1 3 7 6
  • 1 3 2 6 7 4
  • 1 2 4 3 6 7
  • 1 2 3 4 6 7