资源简介
深度优先遍历,广度优先遍历,Dijkstra算法,Floyd算法,Prim算法,WelshPowell着色算法。
代码片段和文件信息
‘‘‘
do something about graph theory.
author: Eric Gao
Data: 2016.05.06--2016.05.08
‘‘‘
# coding:utf-8
global inf
inf = float(‘inf‘)
class Graph:
def __init__(self GraphKind = False AdjMarix=[[]] vernum=0 edgenum=0):
# GraphKind: False presents undirected graph; True presents directed graph.
self.GraphKind = GraphKind
self.AdjMarix = AdjMarix
self.vernum = len(AdjMarix)
self.vertexs = range(self.vernum)
self.edgenum = edgenum
for i in range(self.vernum):
for j in range(self.vernum):
if self.AdjMarix[i][j]>0 and self.AdjMarix[i][j] self.edgenum += 1;
if not self.GraphKind:
self.edgenum /= 2
def NotAdj_and_Adj_Vex(self vex=‘all‘):
adj_vex not_adj_vex = dict() dict()
if vex==‘all‘:
vex = self.vertexs
for
评论
共有 条评论