-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.1.py
More file actions
48 lines (41 loc) · 991 Bytes
/
4.1.py
File metadata and controls
48 lines (41 loc) · 991 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
data = {
"a": ["b","c"],
"b": ["d"],
"c": ["e", "f"],
"d": [],
"e": [],
"f": []
}
# Print levels of graph
def print_graph_row (node, graph):
current = node
que = [current, None]
while len(que) > 0:
current = que.pop(0)
if current == None:
print("***")
if len(que) > 0:
current = que.pop(0)
que.append(None)
else:
break
print(current)
for i in graph[current]:
que.append(i)
print_graph_row("a", data)
# Route Between Nodes
def check_route(start, stop, graph):
if start == stop:
return True
if not start or not stop or not graph:
return False
current = start
que = [current]
while len(que) > 0:
for i in graph[current]:
que.append(i)
current = que.pop(0)
if current == stop:
return True
return False
print(check_route("b","f", data))