Tree: Preorder Traversal

  • + 0 comments

    Java O(n)

     public static void preOrder(Node root) {
            if (root != null) {
                System.out.print(root.data + " ");
                preOrder(root.left);
                preOrder(root.right);
            }
        }