Skip to content

Instantly share code, notes, and snippets.

@fogonthedowns
Created October 14, 2016 21:56
Show Gist options
  • Select an option

  • Save fogonthedowns/1a0f3a51b031851242ee7d5ce92b379e to your computer and use it in GitHub Desktop.

Select an option

Save fogonthedowns/1a0f3a51b031851242ee7d5ce92b379e to your computer and use it in GitHub Desktop.
parse tree
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