topological_sort.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:Visualization-of-popular-algorithms-in-Python 作者: MUSoC 项目源码 文件源码
def CreateResultGraph(sorted_list):
    D = nx.DiGraph()
    for i in range(len(sorted_list)-1): 
        D.add_edge(sorted_list[i], sorted_list[i+1]) 
    pos = nx.spring_layout(D)
    val_map = {}
    val_map[sorted_list[0]] = 'green'
    val_map[sorted_list[len(sorted_list)-1]] = 'red'
    values = [val_map.get(node, 'blue') for node in D.nodes()]
    nx.draw(D, pos, with_labels = True, node_color =values)


#takes input from the file and creates a directed graph
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号