File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ /**
3
+ * A class that represents a graph data structure.
4
+ * It contains an adjacency list which is a dictionary of nodes and their corresponding edges.
5
+ * It has the following methods:
6
+ * - addNode(value: Node) -> Node: adds a new node to the graph
7
+ * - addEdge(fromNode: Node, toNode: Node) -> Bool: adds a directed edge from one node to another
8
+ * - adjacencyList(forNode: Node) -> [Node]? : returns the list of nodes that are adjacent to the given node
9
+ * - calculateInDegreeOfNodes() -> [Node : InDegree]: returns a dictionary of nodes and their corresponding in-degree values
10
+ *
11
+ */
12
+
1
13
public class Graph : CustomStringConvertible {
2
14
public typealias Node = String
3
15
@@ -33,6 +45,13 @@ public class Graph: CustomStringConvertible {
33
45
34
46
extension Graph {
35
47
typealias InDegree = Int
48
+
49
+ /**
50
+ * A method that calculates the in-degree of all the nodes in the graph.
51
+ * It returns a dictionary with the nodes as keys and their corresponding in-degree values as values.
52
+ *
53
+ * - returns: A dictionary of [Node : InDegree]
54
+ */
36
55
37
56
func calculateInDegreeOfNodes( ) -> [ Node : InDegree ] {
38
57
var inDegrees = [ Node: InDegree] ( )
You can’t perform that action at this time.
0 commit comments