CSC301: Printing: Print prefix [21/30] |
public void printPre () { printPre (root, 0); } private static void printPre (Node x, int d) { if (x == null) return; indent (d); StdOut.println (x.key); printPre (x.left, d+1); printPre (x.right, d+1); } private static void indent (int d) { for (int i=0; i<d; i++) StdOut.print (" "); }
This is Pretty Printing
where we use indentation to show depth.