mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
15 lines
451 B
C
15 lines
451 B
C
struct TreeNode* insertIntoBST(struct TreeNode* root, int val){
|
|
if(root == NULL) {
|
|
struct TreeNode *new_val = malloc(sizeof(struct TreeNode));
|
|
new_val->val = val;
|
|
new_val->left = new_val->right = NULL;
|
|
return new_val;
|
|
} else {
|
|
if (root->val >= val)
|
|
root->left = insertIntoBST(root->left, val);
|
|
else
|
|
root->right = insertIntoBST(root->right, val);
|
|
}
|
|
return root;
|
|
}
|