CSC403: Printing: Print postfix with a loop [6/10] |
public void printPost () { Stack<int> r = new Stack<> (); // keys to print out Stack<Node> s = new Stack<> (); // nodes for the traversal s.push (root); while (!s.isEmpty ()) { Node x = s.pop (); if (x == null) continue; r.push (x.key); s.push (x.left); s.push (x.right); } while (!r.isEmpty ()) StdOut.print (r.pop () + " "); StdOut.println (); }
Print postfix with a loop
Hmmm.