Binary search tree is given. Find element in a tree.
Definition of a tree:
// Java
class TreeNode
{
public:
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) {
val = x;
left = NULL;
right = NULL;
};// C++
class TreeNode
{
public:
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};Implement function Find that returns pointer to the element found. If element does not exist, return NULL.
// Java
TreeNode Find(TreeNode tree, int element)// C++
TreeNode* Find(TreeNode *tree, int element)
Function Find with element = 9 returns pointer to the node with value 9.