从二叉树中收集某个范围内的值?

时间:2014-11-03 00:14:24

标签: python recursion binary-tree binary-search-tree

例如{Range:4,6}将返回[4,5,5,6]:

enter image description here

1 个答案:

答案 0 :(得分:1)

def allInRange(bst, left, right):
    if bst is EmptyValue:
        return
    if left <= bst.root <= right:
        print(bst.root)
    allInRange(bst.left, left, right)
    allInRange(bst.right, left, right)