#3906. [GESP202606 六级 C++] 第 13 题

[GESP202606 六级 C++] 第 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;
}

{{ select(1) }}

  • root->left = insertNode(root->left, x);
  • root = insertNode(root->left, x);
  • root->right = insertNode(root->left, x);
  • insertNode(root->left, x);