Created
March 14, 2015 04:04
-
-
Save lettergram/6d92251cd7a96b6f9c8c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
''' | |
Level Order Traversal | |
''' | |
def LevelOrder(self, root): | |
if root is None: | |
pass | |
else: | |
q = Queue.Queue() | |
currLevelCount = 1 | |
nextLevelCount = 0 | |
q.put(root) | |
while not q.empty(): | |
root = q.get() | |
currLevelCount -= 1 | |
if root is not None: | |
print(root.data), | |
q.put(root.left) | |
q.put(root.right) | |
nextLevelCount += 2 | |
if currLevelCount is 0: | |
print "" | |
currLevelCount = nextLevelCount | |
nextLevelCount = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment