You are viewing a single comment's thread. Return to all comments →
Java Solution. Simple Breadth First Solution. The key is to remember to use a Queue and the rest will fall in line.
void LevelOrder(Node root) { if (root == null) return;
Queue<Node> q = new LinkedList<>(); q.add(root); while (!q.isEmpty()){ Node temp = q.poll(); System.out.print(temp.data + " "); if (temp.left != null) q.offer(temp.left); if (temp.right != null) q.offer(temp.right); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Level Order Traversal
You are viewing a single comment's thread. Return to all comments →
Java Solution. Simple Breadth First Solution. The key is to remember to use a Queue and the rest will fall in line.
void LevelOrder(Node root) { if (root == null) return;