e-olymp
Competitions

class Tree

Tree Minimum element

Binary search tree is given. Return the pointer to the minimum element.

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 Minimum that returns pointer to the element with minimum value in the tree.

// Java
TreeNode Minimum(TreeNode tree)
// C++
TreeNode* Minimum(TreeNode *tree)

Example

prb10061.gif

Function Minimum returns pointer to the node with value 2 - the vertex with minimum value in the tree.

Time limit 1 second
Memory limit 128 MiB
Author Mykhailo Medvediev