mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-07-28 03:42:49 +00:00
28 lines
460 B
C
28 lines
460 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);
|
|
}
|
|
}
|