CSC301: Printing: Print level-order in a loop [30/30] |
public void printLevel () { Queue<Node> q = new Queue<> (); q.enqueue (root); while (!q.isEmpty ()) { Node x = q.dequeue (); if (x == null) continue; StdOut.print (x.key + " "); q.enqueue (x.left); q.enqueue (x.right); } StdOut.println (); }
Print level-order in a loop: not bad
Postfix and infix are bad.