from trees import Tree, Node def isBST(root, left=None, right=None): if root is None: return True if left is not None and left.data >= root.data: return False if right is not None and right.data < root.data: return False return (isBST(root.left, left, root) and isBST(root.right, root, right)) t = Tree(5) t.insertLeft(2) t.insertRight(4) root = t.getRoot() t.inOrder(root) print(isBST(root))
current = stack.pop() print(current.data) current = current.right else: done = True def inOrderRec2(root): stack = deque() tmp = root stack.append(tmp) while stack.__len__() > 0: tmp = stack[-1] if tmp.left != None: stack.append(tmp.left) tmp = tmp.left data = stack.pop() print(data.data) if tmp.right != None: stack.ap t = Tree(5) t.insertLeft(2) t.insertRight(7) root = t.getRoot() inOrder(root) inOrderRec(root)