-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.py
More file actions
24 lines (24 loc) · 790 Bytes
/
graph.py
File metadata and controls
24 lines (24 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class graph :
def __init__(self,the_graph=None):
if the_graph is None:
the_graph = {}
self.the_graph = the_graph
def AddEdge(self, edge):
edge = set(edge)
(start,end) = tuple(edge)
if start in self.the_graph:
self.the_graph[start].append(end)
else:
self.the_graph[start] = [end]
def GetEdges(self):
listedge = []
for start in self.the_graph :
for end in self.the_graph[start]:
if {start,end} not in listedge:
listedge.append({start,end})
return listedge
def GetNode(self):
nodes = []
for node in self.the_graph.keys():
nodes.append(node)
return node