Created
June 9, 2017 09:56
-
-
Save AndrejJurkin/0c09e7f9fd297c564452f3271c40c20a to your computer and use it in GitHub Desktop.
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
public void bfs(TreeNode root) { | |
if (root == null) { | |
return; | |
} | |
Queue<TreeNode> queue = new LinkedList<>(); | |
queue.add(root); | |
while(!queue.isEmpty()) { | |
TreeNode node = queue.remove(); | |
System.out.print(node.element + " "); | |
if(node.left != null) { | |
queue.add(node.left); | |
} | |
if(node.right != null) { | |
queue.add(node.right); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment