GESP C++ 真题 · 逐题精解
首页C++六级真题 › 2026年6月 › 第13题

GESP 2026年6月 C++六级 单选题 第13题

C++六级单选题2026年6月第13题

所属知识点:简单背包问题 难度要求:— 考频:—

下面代码实现二叉搜索树的插入操作(假设树中不存在重复值),横线处应填写( )。
TreeNode* insertNode(TreeNode* root, int x) {
    if (root == nullptr) {
        return new TreeNode(x);
    }
    if (x < root->val) {
        ________________________
    } else {
        root->right = insertNode(root->right, x);
    }
    return root;
}

正确答案:A

题目解析
BST 中小于当前节点的值要插到左子树,并把递归结果接回 root->left:root->left = insertNode(root->left, x),选 A。B 错误地改了 root;C 接到了右边;D 没有把返回值接回去(新节点丢失)。💡 递归建树要「接住返回值」,否则插入无效。

想系统刷完 GESP C++ 1~8 级真题,并查看每道题的逐题精讲?

进入 GESPPASS 开始练习