Review Swift codes (#1150)

* feat(swift): review for chapter_computational_complexity

* feat(swift): review for chapter_data_structure

* feat(swift): review for chapter_array_and_linkedlist

* feat(swift): review for chapter_stack_and_queue

* feat(swift): review for chapter_hashing

* feat(swift): review for chapter_tree

* feat(swift): add codes for heap article

* feat(swift): review for chapter_heap

* feat(swift): review for chapter_graph

* feat(swift): review for chapter_searching

* feat(swift): review for chapter_sorting

* feat(swift): review for chapter_divide_and_conquer

* feat(swift): review for chapter_backtracking

* feat(swift): review for chapter_dynamic_programming

* feat(swift): review for chapter_greedy

* feat(swift): review for utils

* feat(swift): update ci tool

* feat(swift): trailing closure

* feat(swift): array init

* feat(swift): map index
This commit is contained in:
nuomi1
2024-03-20 21:15:39 +08:00
committed by GitHub
parent 300a781fab
commit 7359a7cb4b
55 changed files with 293 additions and 224 deletions

View File

@@ -43,8 +43,8 @@ public class GraphAdjList {
fatalError("参数错误")
}
// vet1 - vet2
adjList[vet1]?.removeAll(where: { $0 == vet2 })
adjList[vet2]?.removeAll(where: { $0 == vet1 })
adjList[vet1]?.removeAll { $0 == vet2 }
adjList[vet2]?.removeAll { $0 == vet1 }
}
/* */
@@ -65,19 +65,16 @@ public class GraphAdjList {
adjList.removeValue(forKey: vet)
// vet
for key in adjList.keys {
adjList[key]?.removeAll(where: { $0 == vet })
adjList[key]?.removeAll { $0 == vet }
}
}
/* */
public func print() {
Swift.print("邻接表 =")
for pair in adjList {
var tmp: [Int] = []
for vertex in pair.value {
tmp.append(vertex.val)
}
Swift.print("\(pair.key.val): \(tmp),")
for (vertex, list) in adjList {
let list = list.map { $0.val }
Swift.print("\(vertex.val): \(list),")
}
}
}