标签:child none name def ges nod tree .so for
class Tree:
def __init__(self,name,sort):
self.name = name
self.sort = sort
self.children = {}
def create(self,node_map,edge):
l,r,k = edge
l_node = node_map.get(l)
if l_node == None:
l_node = Tree(l,0)
node_map[l] = l_node
r_node = node_map.get(r)
if r_node == None:
r_node = Tree(r,0)
node_map[r] = r_node
if k == ‘left‘:
l_node.children[r] = r_node
return l
else:
r_node.children[l] = l_node
return r
nodes = [‘C‘,‘B‘,‘A‘,‘D‘]
edges = [(‘A‘,‘B‘,‘left‘),(‘B‘,‘C‘,‘left‘),(‘D‘,‘B‘,‘right‘)]
def get_order(nodes,edges):
vs = [0]*len(edges)
edge_dict = dict(zip(edges,vs))
n = nodes[0]
node_dict = {}
node_dict[n] = 0
for l,r,t in edge_dict:
if edge_dict[(l,r,t)] == 0:
if node_dict.get(l)
标签:child none name def ges nod tree .so for
原文地址:http://www.cnblogs.com/learnthenknow/p/7544613.html