We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6bc50e5 commit ea777fbCopy full SHA for ea777fb
Minimum Spanning Tree/MinimumSpanningTree.playground/Sources/Graph.swift
@@ -37,17 +37,11 @@ public struct Graph<T: Hashable>: CustomStringConvertible {
37
vertices.insert(v1)
38
vertices.insert(v2)
39
40
- if let _ = adjList[v1] {
41
- adjList[v1]?.append((vertex: v2, weight: w))
42
- } else {
43
- adjList[v1] = [(vertex: v2, weight: w)]
44
- }
+ adjList[v1] = adjList[v1] ?? []
+ adjList[v1]?.append((vertex: v2, weight: w))
45
46
- if let _ = adjList[v2] {
47
- adjList[v2]?.append((vertex: v1, weight: w))
48
49
- adjList[v2] = [(vertex: v1, weight: w)]
50
+ adjList[v2] = adjList[v2] ?? []
+ adjList[v2]?.append((vertex: v1, weight: w))
51
}
52
53
public mutating func addEdge(_ edge: Edge<T>) {
0 commit comments