|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
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([1,2,3,4]) returns True of False
问题2,方法trypath来验证给定路径是否有效?例如;trypath([1,2,3,4])返回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([1,2,5,4,3]))
- print(g.trypath([1,3,5,4,3]))
- print(g.trypath([1,2,4,3,5]))
- print(g.trypath([1,2,4,3,2,5]))
复制代码 |
|