mirror of
https://github.com/TheAlgorithms/C
synced 2025-04-23 22:03:22 +03:00
23 lines
439 B
C
23 lines
439 B
C
/**
|
|
* Definition for a binary tree node.
|
|
* struct TreeNode {
|
|
* int val;
|
|
* struct TreeNode *left;
|
|
* struct TreeNode *right;
|
|
* };
|
|
*/
|
|
|
|
|
|
struct TreeNode* searchBST(struct TreeNode* root, int val){
|
|
if(!root)
|
|
return NULL;
|
|
|
|
if (root->val == val) {
|
|
return root;
|
|
} else if (root->val > val) {
|
|
return searchBST(root->left, val);
|
|
} else {
|
|
return searchBST(root->right, val);
|
|
}
|
|
}
|