Created
October 9, 2016 09:03
-
-
Save tmosest/d67c4f251fef0c6c218535ac54ec96e2 to your computer and use it in GitHub Desktop.
Hackerrank: Day 23: BST Level-Order Traversal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void levelOrder(Node root){ | |
Queue<Node> queue = new LinkedList(); | |
queue.add(root); | |
while(!queue.isEmpty()){ | |
Node current = queue.remove(); | |
System.out.print(current.data+" "); | |
if (current.left!=null) queue.add(current.left); | |
if (current.right!=null) queue.add(current.right); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment