You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Graph/Graph.playground/Pages/Adjacency List.xcplaygroundpage/Contents.swift
+39-12Lines changed: 39 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -4,34 +4,51 @@ A graph implementation, using an adjacency list.
4
4
5
5
In an adjacency list implementation, each vertex stores an array of edges, indicating to which vertices it has an edge (note the directionality). The edge stores the source and destination vertices, as well as a weight.
6
6
7
-
Connected vertices in this implementation is O(1).
7
+
Connecting vertices in this implementation is O(1).
8
8
9
9
*/
10
10
11
+
varuniqueIDCounter:Int=0
12
+
11
13
publicstructGraphEdge<T>{
12
14
publicletfrom:GraphVertex<T>
13
15
publicletto:GraphVertex<T>
14
16
publicletweight:Double
15
17
}
16
18
19
+
17
20
publicstructGraphVertex<T>{
18
21
publicvardata:T
19
-
publicprivate(set)varedges:[GraphEdge<T>]=[] // This is a simple adjacency list, rather than matrix
22
+
publicprivate(set)varedges:[GraphEdge<T>]=[] // This is an adjacency list, rather than matrix
0 commit comments