#10400. szjy_6_树_020

szjy_6_树_020

szjy_6_树_020

给定的树是一棵二叉搜索树。阅读代码,程序输出是( )。

#include <iostream>
using namespace std;

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

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

int main() {
Node a{5}, b{3}, c{7}, d{1}, e{9};
a.left = &b;  a.right = &c;
b.left = &d;
c.right = &e;
show(&a);
}

{{ select(1) }}

  • 1 3 5 7 9
  • 5 3 1 7 9
  • 1 3 9 7 5
  • 9 7 5 3 1