1

So, in the case of these two functions, I input something like:

 BSTTree.maxValue(BSTTree.root)

and let's say the BST looked something like this:

     6
    / \
   3   7
        \
         8
          \ 
           9

for max value it returns a "None" value. If i print out each root value, it will stop printing at 8... :/

Any ideas?

def maxValue(self, root):

    if (root.right is None):
        return root.value

    if (root.right is not None):

        self.maxVal(root.right)
        print root.value




def minValue(self, root):

     if (root.left is None):
        return root.value

     else:
         if (root.left is not None):
            self.minValue(root.left)
Skorpius
  • 2,135
  • 2
  • 26
  • 31

1 Answers1

0

The following:

self.maxVal(root.right)

should read

return self.maxVal(root.right)

Otherwise you're ignoring the return value from the recursive call.

The same goes for minValue().

P.S. Since neither method needs self, you might want to consider turning them into static methods.

Community
  • 1
  • 1
NPE
  • 486,780
  • 108
  • 951
  • 1,012