求助,关于矩阵问题
1.method qadj(i,j) to judge whether thre is a direct path (i.e. edge) from i to j.?example: qadj(2,5) returns True or False问题1,方法qad判断是否从i到j为直接路径?例如;qadj(2,5) 返回 True 或 False
2.method trypath(path) to verify given path is valid (traversable) or not. Path is given as a list of int?example: trypath() returns True of False
问题2,方法trypath来验证给定路径是否有效?例如;trypath()返回True或False
求助,请能帮我完善一下整体代码围绕上述两个问题,感激不尽
class MyGraphMatrix2(MyGraphMatrix):
def qadj(self,i,j):
###CODE ###
def trypath(self,l):
###CODE ###
g = MyGraphMatrix2(5)
g.adj(1,2)
g.adj(1,5)
g.adj(2,1)
g.adj(2,5)
g.adj(2,3)
g.adj(2,4)
g.adj(3,2)
g.adj(3,4)
g.adj(4,2)
g.adj(4,5)
g.adj(4,3)
g.adj(5,4)
g.adj(5,1)
g.adj(5,2)
print(g.adjbody)
print(g.trypath())
print(g.trypath())
print(g.trypath())
print(g.trypath())
页:
[1]