mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
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:
@ -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();
|
||||
|
||||
Reference in New Issue
Block a user