本文整理汇总了C++中TGraph::Bfs方法的典型用法代码示例。如果您正苦于以下问题:C++ TGraph::Bfs方法的具体用法?C++ TGraph::Bfs怎么用?C++ TGraph::Bfs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TGraph
的用法示例。
在下文中一共展示了TGraph::Bfs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
TGraph graph(5);
graph.Insert(0, 1, 6);
graph.Insert(0, 3, 7);
graph.Insert(1, 2, 5);
graph.Insert(1, 3, 8);
graph.Insert(1, 4, -4);
graph.Insert(2, 1, -2);
graph.Insert(3, 2, -3);
graph.Insert(3, 4, 9);
graph.Insert(4, 2, 7);
graph.Insert(4, 0, 2);
cout << "DFS: ";
graph.Dfs();
cout << endl;
cout << "BFS: ";
graph.Bfs();
cout << endl;
TGraph copy = graph.Copy();
cout << "copy DFS: ";
copy.Dfs();
cout << endl;
cout << "copy BFS: ";
copy.Bfs();
cout << endl;
int src = 0;
cout << "Bellman Ford from src " << src << endl;
graph.BellmanFord(src);
TGraph nonNegGraph(5);
nonNegGraph.Insert(0, 1, 10);
nonNegGraph.Insert(0, 3, 5);
nonNegGraph.Insert(1, 2, 1);
nonNegGraph.Insert(1, 3, 2);
nonNegGraph.Insert(2, 4, 4);
nonNegGraph.Insert(3, 1, 3);
nonNegGraph.Insert(3, 2, 9);
nonNegGraph.Insert(3, 4, 2);
nonNegGraph.Insert(4, 0, 7);
nonNegGraph.Insert(4, 2, 6);
cout << "non-neg BFS: ";
nonNegGraph.Bfs();
cout << endl;
cout << "Dijkstra from src " << src << endl;
nonNegGraph.Dijkstra(src);
return 0;
}