hello-algo
hello-algo copied to clipboard
feat: add dart code for chapter_graph
If this PR is related to coding or code translation, please fill out the checklist and paste the console outputs to the PR.
- [x] I've tested the code and ensured the outputs are the same as the outputs of reference codes.
- [x] I've checked the codes (formatting, comments, indentation, file header, etc) carefully.
- [x] The code does not rely on a particular environment or IDE and can be executed on a standard system (Win, macOS, Ubuntu).
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
hello-algo | ⬜️ Ignored (Inspect) | May 15, 2023 9:48am |
Here is the terminal output.
graph_adjacency_list.dart
初始化后,图为
邻接表 =
1: [3, 5],
3: [1, 2],
5: [1, 2, 4],
2: [3, 5, 4],
4: [2, 5],
添加边 1-2 后,图为
邻接表 =
1: [3, 5, 2],
3: [1, 2],
5: [1, 2, 4],
2: [3, 5, 4, 1],
4: [2, 5],
删除边 1-3 后,图为
邻接表 =
1: [5, 2],
3: [2],
5: [1, 2, 4],
2: [3, 5, 4, 1],
4: [2, 5],
添加顶点 6 后,图为
邻接表 =
1: [5, 2],
3: [2],
5: [1, 2, 4],
2: [3, 5, 4, 1],
4: [2, 5],
6: [],
删除顶点 3 后,图为
邻接表 =
1: [5, 2],
5: [1, 2, 4],
2: [5, 4, 1],
4: [2, 5],
6: [],
graph_adjacency_matrix.dart
初始化后,图为
顶点列表 =
[1, 3, 2, 5, 4]
邻接矩阵 =
[
[0, 1, 0, 1, 0],
[1, 0, 1, 0, 0],
[0, 1, 0, 1, 1],
[1, 0, 1, 0, 1],
[0, 0, 1, 1, 0],
]
添加边 1-2 后,图为
顶点列表 =
[1, 3, 2, 5, 4]
邻接矩阵 =
[
[0, 1, 1, 1, 0],
[1, 0, 1, 0, 0],
[1, 1, 0, 1, 1],
[1, 0, 1, 0, 1],
[0, 0, 1, 1, 0],
]
删除边 1-3 后,图为
顶点列表 =
[1, 3, 2, 5, 4]
邻接矩阵 =
[
[0, 0, 1, 1, 0],
[0, 0, 1, 0, 0],
[1, 1, 0, 1, 1],
[1, 0, 1, 0, 1],
[0, 0, 1, 1, 0],
]
添加顶点 6 后,图为
顶点列表 =
[1, 3, 2, 5, 4, 6]
邻接矩阵 =
[
[0, 0, 1, 1, 0, 0],
[0, 0, 1, 0, 0, 0],
[1, 1, 0, 1, 1, 0],
[1, 0, 1, 0, 1, 0],
[0, 0, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0],
]
删除顶点 3 后,图为
顶点列表 =
[1, 2, 5, 4, 6]
邻接矩阵 =
[
[0, 1, 1, 0, 0],
[1, 0, 1, 1, 0],
[1, 1, 0, 1, 0],
[0, 1, 1, 0, 0],
[0, 0, 0, 0, 0],
]
graph_bfs.dart
初始化后,图为
邻接表 =
0: [1, 3],
1: [0, 2, 4],
3: [0, 4, 6],
2: [1, 5],
4: [1, 3, 5, 7],
5: [2, 4, 8],
6: [3, 7],
7: [4, 6, 8],
8: [5, 7],
广度优先遍历(BFS)顶点序列为
[0, 1, 3, 2, 4, 6, 5, 7, 8]
graph_dfs.dart
初始化后,图为
邻接表 =
0: [1, 3],
1: [0, 2],
3: [0],
2: [1, 5],
5: [2, 4, 6],
4: [5],
6: [5],
深度优先遍历(DFS)顶点序列为
[0, 1, 2, 5, 4, 6, 3]