You are viewing a single comment's thread. Return to all comments →
Java solution:
public static void levelOrder(Node root) { Queue<Node> queue = new LinkedList<>(); queue.add(root); Node current = null; while(!queue.isEmpty()){ for(int i=1; i<= queue.size(); i++){ current = queue.poll(); // visit the current node System.out.print(current.data+" "); // add next nodes to queue if(current.left != null) queue.add(current.left); if(current.right != null) queue.add(current.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: