找代码废了很大的时间,有些代码存在问题,或者是不好理解,这个是python的,C或Java的较多。
理解程序还是费了我不少脑细胞的,多亏了有裘老师的帮助啊,后续会跟进的,努力加油!
#裘宗燕数据结构中的aoe网络代码
"""topological sort of direct graph
"""
class Graph: #basic graph class, using adjacent matrix
def __init__(self, mat, unconn = 0):
vnum1 = len(mat) #行数
for x in mat:
if len(x) != vnum1: # Check square matrix检查是否为方阵
raise ValueError("Argumentfor 'GraphA' is bad.")
self.mat = [mat[i][:] for i inrange(vnum1)]
self.unconn = unconn
self.vnum = vnum1
def _out_edges(mat, vi, unconn):
edges = []
row = mat[vi]
for i in range(len(row)):
if row[i] != unconn:
#prin