コード例 #1
0
ファイル: BFS.py プロジェクト: JC5137/CLRS
 def BFS(self, Graph, start):
     self.__setAttribute(Graph)
     self.color[start] = 0
     self.distance[start] = 0
     self.prev[start] = None
     Q = Queue(len(Graph.vertexs))
     Q.EnQueue(start)
     while not Q.IsEmpty():
         u = Q.DeQueue()
         for v in Graph.edges[u]:
             if self.color[v] == -1:
                 self.color[v] = 0
                 self.distance[v] = self.distance[u] + 1
                 self.prev[v] = u
                 Q.EnQueue(v)
         self.color[u] = 1