1

I' am searching values in a binary search tree, but the function keeps returning None, and the function is successfully finding/not finding the value

class BinaryTree():

    def __init__(self, value):
        self.left = None
        self.right = None
        self.value = value

    def find(self, valueToFind, parent, vist_counter=0):
       if parent is None:                                             
           return valueToFind, -1
           vist_counter += 1
       if parent.value == valueToFind:
           return valueToFind, vist_counter
       if valueToFind <= parent.value:                                
            self.find(valueToFind, parent.left, vist_counter)
       elif valueToFind > parent.value:                                
           self.find(valueToFind, parent.right, vist_counter)
leakybytes
  • 359
  • 4
  • 12

1 Answers1

1

Your code is not clear. However, as far as I understand, you should return the function call on the last two statements.

return self.find(valueToFind, parent.left, vist_counter)
Burak Özdemir
  • 510
  • 8
  • 18