Binary search tree is given. Return the pointer to the maximum element.
Definition of a tree:
class TreeNode {
public int val;
public TreeNode left;
public TreeNode right;
TreeNode(int x) {
val = x;
left = null;
right = null;
}
}class TreeNode {
public:
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};Implement function Maximum that returns pointer to the element with maximum value in the tree.
TreeNode Maximum(TreeNode tree)TreeNode* Maximum(TreeNode *tree)
Function Maximum returns pointer to the node with value 16 - the vertex with maximum value in the tree.