#include #include struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; }; struct TreeNode* searchBST(struct TreeNode*, int); struct TreeNode* searchBST(struct TreeNode* root, int val){ if (root == NULL) { return NULL; } else if (root->val == val) { return root; } else if (root->val > val) { return searchBST(root->left, val); } else { return searchBST(root->right, val); } } int main() { struct TreeNode *t2 = malloc(sizeof(struct TreeNode)); t2->val = 2; t2->left = NULL; t2->right = NULL; struct TreeNode *t3 = malloc(sizeof(struct TreeNode)); t3->val = 3; t3->left = NULL; t3->right = NULL; struct TreeNode *t = malloc(sizeof(struct TreeNode)); t->val = 1; t->left = t2; t->right = t3; printf("Expected: 1 (as root of tree)\n"); printf("Got: %d\n", searchBST(t, 1)->val); return 0; }