Add Dart codes to the documents. (#529)

This commit is contained in:
Yudong Jin
2023-06-02 02:40:26 +08:00
committed by GitHub
parent 041a989d33
commit 025051c81b
38 changed files with 849 additions and 96 deletions

View File

@ -88,6 +88,12 @@
```
=== "Dart"
```dart title="graph_adjacency_matrix.dart"
[class]{GraphAdjMat}-[func]{}
```
## 基于邻接表的实现
设无向图的顶点总数为 $n$ 、边总数为 $m$ ,则有:
@ -179,6 +185,12 @@
[class]{GraphAdjList}-[func]{}
```
=== "Dart"
```dart title="graph_adjacency_list.dart"
[class]{GraphAdjList}-[func]{}
```
## 效率对比
设图中共有 $n$ 个顶点和 $m$ 条边,下表为邻接矩阵和邻接表的时间和空间效率对比。

View File

@ -84,6 +84,12 @@ BFS 通常借助「队列」来实现。队列具有“先入先出”的性质
[class]{}-[func]{graphBFS}
```
=== "Dart"
```dart title="graph_bfs.dart"
[class]{}-[func]{graphBFS}
```
代码相对抽象,建议对照以下动画图示来加深理解。
=== "<1>"
@ -219,6 +225,14 @@ BFS 通常借助「队列」来实现。队列具有“先入先出”的性质
[class]{}-[func]{graphDFS}
```
=== "Dart"
```dart title="graph_dfs.dart"
[class]{}-[func]{dfs}
[class]{}-[func]{graphDFS}
```
深度优先遍历的算法流程如下图所示,其中:
- **直虚线代表向下递推**,表示开启了一个新的递归方法来访问新顶点;