其英文全称为Breadth First Search,简称BFS。...self.node_neighbors[v].append(u)
def nodes(self):
return self.node_neighbors.keys()
def breadth_first_search...g.add_edge((3, 6))
g.add_edge((3, 7))
g.add_edge((6, 7))
print ("Original nodes: ", g.nodes())
order = g.breadth_first_search...(1)
print ("Breadth-First-Search order: ", order)
运行结果:
Original nodes: dict_keys([1, 2, 3, 4, 5, 6,...7, 8])
Breadth-First-Search order: [1, 2, 3, 4, 5, 6, 7, 8]