python构造图的方法
只要各顶点及边都确定了,就可以构建出图。
一、图类
1 | class Graph: |
二、构建图
1、邻接矩阵构建无向图
1 | nodes = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] |
2、邻接矩阵构建有向图
1 | nodes = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] |
3、邻接表构建图
1 | nodes = ['A', 'B', 'C', 'D', 'E', 'F', 'G'] |
只要各顶点及边都确定了,就可以构建出图。
1 | class Graph: |
1 | nodes = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] |
1 | nodes = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] |
1 | nodes = ['A', 'B', 'C', 'D', 'E', 'F', 'G'] |