我'我在二叉搜索树中搜索值,但该函数保持返回None,并且该函数成功查找/未找到值
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)
答案 0 :(得分:1)
您的代码不清楚。但是,据我所知,你应该在最后两个语句中返回函数调用。
return self.find(valueToFind, parent.left, vist_counter)