Update graph codes

This commit is contained in:
krahets
2023-02-15 03:35:54 +08:00
parent 5541fe5964
commit 8e0080f003
6 changed files with 29 additions and 90 deletions

View File

@ -23,9 +23,11 @@ class Vertex: Hashable {
/* */
class GraphAdjList {
// vertices adjList Vertex
private var adjList: [Vertex: Set<Vertex>] // 使
// 使
// adjList Vertex
private var adjList: [Vertex: Set<Vertex>]
/* */
init(edges: [[Vertex]]) {
adjList = [:]
//
@ -66,7 +68,7 @@ class GraphAdjList {
if adjList[vet] != nil {
return
}
// HashSet
//
adjList[vet] = []
}
@ -75,9 +77,9 @@ class GraphAdjList {
if adjList[vet] == nil {
fatalError("参数错误")
}
// vet HashSet
// vet
adjList.removeValue(forKey: vet)
// HashSet vet
// vet
for key in adjList.keys {
adjList[key]?.remove(vet)
}