diff --git a/graphs/Directed (Weighted) Graph b/graphs/Directed and Undirected (Weighted) Graph similarity index 95% rename from graphs/Directed (Weighted) Graph rename to graphs/Directed and Undirected (Weighted) Graph index 0b3b3a2cb..74d741f5e 100644 --- a/graphs/Directed (Weighted) Graph +++ b/graphs/Directed and Undirected (Weighted) Graph @@ -95,6 +95,16 @@ class DirectedGraph: d.append(__[1]) visited.append(__[1]) return visited + def in_degree(self, u): + count = 0 + for _ in self.graph: + for __ in self.graph[_]: + if __[1] == u: + count += 1 + return count + + def out_degree(self, u): + return len(self.graph[u]) class Graph: @@ -202,3 +212,5 @@ class Graph: d.append(__[1]) visited.append(__[1]) return visited + def degree(self, u): + return len(self.graph[u])