feat: Add C++ code for the graph bfs and dfs (#401)

* Add C++ code for the graph bfs and dfs

* Add C++ code for the graph bfs and dfs
This commit is contained in:
Yudong Jin
2023-03-02 18:57:33 +08:00
committed by GitHub
parent 4f941e3d99
commit 33c797efeb
11 changed files with 241 additions and 88 deletions

View File

@ -84,7 +84,8 @@ public class graph_adjacency_list {
public static void main(String[] args) {
/* 初始化无向图 */
Vertex[] v = Vertex.valsToVets(new int[] { 1, 3, 2, 5, 4 });
Vertex[][] edges = { { v[0], v[1] }, { v[0], v[3] }, { v[1], v[2] }, { v[2], v[3] }, { v[2], v[4] }, { v[3], v[4] } };
Vertex[][] edges = { { v[0], v[1] }, { v[0], v[3] }, { v[1], v[2] },
{ v[2], v[3] }, { v[2], v[4] }, { v[3], v[4] } };
GraphAdjList graph = new GraphAdjList(edges);
System.out.println("\n初始化后图为");
graph.print();