码迷,mamicode.com
首页 > 其他好文 > 详细

ddd

时间:2017-09-18 19:44:50      阅读:173      评论:0      收藏:0      [点我收藏+]

标签: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)

ddd

标签:child   none   name   def   ges   nod   tree   .so   for   

原文地址:http://www.cnblogs.com/learnthenknow/p/7544613.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!