Tree: Preorder Traversal

  • + 0 comments

    Java

    • visit the nodes in a order. left then right.
    • Recursive call on left sub tree.
    • Recursive call on right sub tree.
    public static void preOrder(Node root) {
            if(root != null){
                System.out.print(root.data+" ");
                preOrder(root.left);
                preOrder(root.right);
            }
        }