mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-03 02:43:41 +08:00
feat: add the section of Graph Traversal (#367)
* Graph dev * Add the section of Graph Traversal. * Add missing Vertex.java * Add mkdocs.yml * Update numbering * Fix indentation and update array.md
This commit is contained in:
@@ -89,7 +89,7 @@ comments: true
|
||||
=== "Zig"
|
||||
|
||||
```zig title="graph_adjacency_matrix.zig"
|
||||
|
||||
|
||||
```
|
||||
|
||||
## 9.2.2. 基于邻接表的实现
|
||||
@@ -119,6 +119,12 @@ comments: true
|
||||
|
||||
基于邻接表实现图的代码如下所示。
|
||||
|
||||
!!! question "为什么需要使用顶点类 `Vertex` ?"
|
||||
|
||||
如果我们直接通过顶点值来区分不同顶点,那么值重复的顶点将无法被区分。
|
||||
如果建立一个顶点列表,用索引来区分不同顶点,那么假设我们想要删除索引为 `i` 的顶点,则需要遍历整个邻接表,将其中 $> i$ 的索引全部执行 $-1$ ,这样的操作是比较耗时的。
|
||||
因此,通过引入顶点类 `Vertex` ,每个顶点都是唯一的对象,这样在删除操作时就无需改动其余顶点了。
|
||||
|
||||
=== "Java"
|
||||
|
||||
```java title="graph_adjacency_list.java"
|
||||
|
||||
Reference in New Issue
Block a user