第38766题 单选题
根据下面二叉树和给定的代码, 给定以下二叉搜索树,调用函数 search(root,7) 时,输出的结果是( )。
#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 }}%
答案解析