Tree: Preorder Traversal

  • + 1 comment
    def preOrder(root):
        stack = [root]
        while stack:
            curr_node = stack.pop()
            print(curr_node.info, end=' ')
            if curr_node.right:
                stack.append(curr_node.right)
            if curr_node.left:
                stack.append(curr_node.left)