python图的应用
来源:互联网 发布:linux 启动oracle进程 编辑:程序博客网 时间:2024/05/18 01:09
一 图的结构
二 代码
def searchGraph(graph,start,end):
results =[]
generatePath(graph,[start],end,results)
results.sort(key =lambda x:len(x))
return results
def generatePath(graph,path,end,results):
state = path[-1]
if state == end:
results.append(path)
else:
for arc in graph[state]:
if arc notin path:
generatePath(graph,path +[arc],end ,results)
if __name__ =='__main__':
Graph={'A':['B','C','D'],
'B':['E'],
'C':['D','F'],
'D':['B','E','G'],
'E':[],
'F':['D','G'],
'G':['E']}
r = searchGraph(Graph,'A','E')
print("******************")
print(' path A to E')
print("******************")
for i in r:
print(i)
三运行结果
******************
path A to E
******************
['A', 'B', 'E']
['A', 'D', 'E']
['A', 'C', 'D', 'E']
['A', 'D', 'B', 'E']
['A', 'D', 'G', 'E']
['A', 'C', 'D', 'B', 'E']
['A', 'C', 'D', 'G', 'E']
['A', 'C', 'F', 'D', 'E']
['A', 'C', 'F', 'G', 'E']
['A', 'C', 'F', 'D', 'B', 'E']
['A', 'C', 'F', 'D', 'G', 'E']
阅读全文
0 0
- python图的应用
- python的实例应用
- Python的应用集合
- python gearman的应用
- Python 的应用
- Python字典的应用
- python的应用范围
- 应用Python的公司
- python的应用
- python的全局变量应用
- python集合的应用
- Python 的应用
- python format的应用
- Python在工作中的应用
- PYTHON的应用
- python的高级应用
- python *的应用
- python sqlalchemy的应用
- 设计模式之禅12
- WCF学习系列之[老老实实学WCF] 第一篇 Hello WCF (转自CSDN宋业飞)
- python3发起一个http请求
- TCP协议中的三次握手和四次挥手(图解)
- Huffman树和编码
- python图的应用
- javascript中闭包的概念
- JDBC---Javaweb过程中的问题及解决方案
- 科学方法定义
- iOS开发—sqlite3的使用
- eclipse启动无响应问题的解决
- python实现二分法查找
- Java中使用JDBC连接SQLserver
- Kubernetes对象之Nodes和 Master与Node的通信