CSC403: Printing: Print level-order in a loop [10/10] |
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.