Created
October 14, 2016 21:56
-
-
Save fogonthedowns/1a0f3a51b031851242ee7d5ce92b379e to your computer and use it in GitHub Desktop.
parse tree
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
| def parse_tree(tree, path): | |
| path = path | |
| if path ==[]: | |
| path.append(str(tree.get_id())) | |
| if tree.is_leaf() is False: | |
| left = tree.get_left() | |
| left_id = str(left.get_id()) | |
| if left.is_leaf() is False: | |
| path.append(left_id) | |
| parse_tree(left, path) | |
| path.pop() | |
| else: | |
| parse_tree(left, path) | |
| right = tree.get_right() | |
| right_id = str(right.get_id()) | |
| if right.is_leaf() is False: | |
| path.append(right_id) | |
| parse_tree(right, path) | |
| else: | |
| path.append(str(tree.get_id())) | |
| print(('.').join(path)) | |
| path.pop() | |
| parse_tree(a, []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment