You are viewing a single comment's thread. Return to all comments →
I used the following code:
public static void levelOrder(Node root) { levelOrder(root, 0); for (Integer key : result.keySet()) { System.out.print(result.get(key)); } } public static void levelOrder(Node root, int level) { if (root == null) { return; } if (result.containsKey(level)) { result.put(level, result.get(level) + root.data + " "); } else { result.put(level, root.data + " "); } levelOrder(root.left, level+1); levelOrder(root.right, level+1); }
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 →
I used the following code: