Tree: Preorder Traversal

  • + 0 comments
    def preOrder(root):
        result = []
        
        def traverse(node):
            if not node:
                return
            result.append(str(node.info))
            traverse(node.left)
            traverse(node.right)
            
        traverse(root)
        print(" ".join(result))