mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Added getting node degree functionality to both directed and undirected graph
Easy to use directed and undirected graph in python 3
This commit is contained in:
parent
e97565d21f
commit
889f8fba3d
@ -95,6 +95,16 @@ class DirectedGraph:
|
|||||||
d.append(__[1])
|
d.append(__[1])
|
||||||
visited.append(__[1])
|
visited.append(__[1])
|
||||||
return visited
|
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:
|
class Graph:
|
||||||
@ -202,3 +212,5 @@ class Graph:
|
|||||||
d.append(__[1])
|
d.append(__[1])
|
||||||
visited.append(__[1])
|
visited.append(__[1])
|
||||||
return visited
|
return visited
|
||||||
|
def degree(self, u):
|
||||||
|
return len(self.graph[u])
|
Loading…
x
Reference in New Issue
Block a user