I'm unfamiliar with how to bubble up a return call from a recursive function call in Python. In this example I'm writing a 'check if something is a binary tree method' which has to return true or false. However if I call it from another function (even when I hit my conditional) I will not get False returned.
How can I ensure that this return call goes all the way up?
def isValidTree(root, tempArr):
if(root.left):
return isValidTree(root.left, tempArr)
if(len(tempArr) == 0):
tempArr.append(root.data)
elif(tempArr[len(tempArr) - 1] >= root.data):
return False
else:
tempArr.append(root.data)
if(root.right):
return isValidTree(root.right, tempArr)
def isBinarySearchTree(root):
print(isValidTree(root, []))