以下代码实现了二叉排序树的哪种操作?
TreeNode* op(TreeNode* root, int val) {
if (root == nullptr) return new TreeNode(val);
if (val < root->val) {
root->left = op(root->left, val);
} else {
root->right = op(root->right, val);
}
return root;
}
- A. 查找
- B. 插入
- C. 删除
- D. 遍历