Weadadada Awda
Weadadada Awda

Reputation: 383

maximum and minimum value of binary tree

I don't understand how this isn't working:

Node* BST::Minimum(Node *curr) {

    if (curr->left != NULL) {
        Minimum(curr->left);
    }

    return curr;

}

I mean I already did insert fine, and printpostorder, inorderr, preorder fine.

Am I doing something silly? This just prints the root node.

Upvotes: 0

Views: 365

Answers (1)

David Schwartz
David Schwartz

Reputation: 182883

You call Minimum and throw its return value away. You want return Minimum(curr->left);.

By the way, I strongly recommend doing this iteratively rather than recursively, like this:

  Node* node = curr;
  while (node->left != NULL)
      node = node->left;
  return node;

Upvotes: 2

Related Questions