Skip to content

Commit

Permalink
Added getting node degree functionality to both directed and undirect…
Browse files Browse the repository at this point in the history
…ed graph

Easy to use directed and undirected graph in python 3
  • Loading branch information
A Safari authored Dec 14, 2018
1 parent e97565d commit 889f8fb
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -202,3 +212,5 @@ class Graph:
d.append(__[1])
visited.append(__[1])
return visited
def degree(self, u):
return len(self.graph[u])

0 comments on commit 889f8fb

Please sign in to comment.