Skip to content

Instantly share code, notes, and snippets.

@touhi99
Created June 30, 2018 21:03
Show Gist options
  • Save touhi99/d4f20bc15301ee015222d15f2697c285 to your computer and use it in GitHub Desktop.
Save touhi99/d4f20bc15301ee015222d15f2697c285 to your computer and use it in GitHub Desktop.
def generate_tree(self, node):
#print(node)
if isinstance(self.find(self.copy_table, node)[1], (list,)):
item = self.find(self.copy_table, node)[1]
item_x = self.find(self.copy_table, node)[2]
item_y = self.find(self.copy_table, node)[3]
self.copy_table.remove(node)
if item_x[0]==0:
x=self.copy_table_reversed[item_x[1]]
else:
x=self.find_tuple(self.copy_table, item_x)
if item_y[0]==0:
y=self.copy_table_reversed[item_y[1]]
else:
y=self.find_tuple(self.copy_table, item_y)
#print(node," ---", x," ----", y)
return (node[0], self.generate_tree(x), self.generate_tree(y))
else:
return (node[0], self.find_terminal(self.copy_table, node)[0][1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment