Tree: Preorder Traversal

  • + 0 comments

    JAVA

    public static void preOrder(Node root) {
    
        if (root == null) {
            return;
        }
        // visit the root
        System.out.print(root.data + " ");
        // traverse the left
        preOrder(root.left);
        // traverse the right
        preOrder(root.right);
    }