第23755题 单选题
给定C++二叉搜索树search函数和指定二叉树,调用search(root,7)的输出结果是()

给定的C++代码

#include <iostream>
using namespace std;

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

TreeNode* search(TreeNode* root, int val) {
    cout << root->val << " ";
    if (root == NULL || root->val == val) return root;
    if (val < root->val)
        return search(root->left, val);
    else
        return search(root->right, val);
}

给定的二叉搜索树结构

        5
      /   \
     3     7
    / \   / \
   2  4  6  8
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析