Skip to content

Commit 00dca1a

Browse files
authored
Update Graph.swift
Added Docstrings for easier understanding for begginers
1 parent e592ed6 commit 00dca1a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Topological Sort/Graph.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
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+
113
public class Graph: CustomStringConvertible {
214
public typealias Node = String
315

@@ -33,6 +45,13 @@ public class Graph: CustomStringConvertible {
3345

3446
extension Graph {
3547
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+
*/
3655

3756
func calculateInDegreeOfNodes() -> [Node : InDegree] {
3857
var inDegrees = [Node: InDegree]()

0 commit comments

Comments
 (0)