Created
February 8, 2018 00:54
-
-
Save tamlt2704/69cd6c73fe97d4903127987917e37e44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g = {1: [2, 3], 2: [4, 5], 3: [6, 7], 6: [7], 7: [9]} | |
arr = [1] | |
visited = [1] | |
while arr: | |
n = arr[0] | |
if n not in g.keys(): | |
print arr | |
arr.pop(0) | |
else: | |
allChildVisited = True | |
for x in g[n]: | |
if x not in visited: | |
arr.insert(0, x) | |
visited.append(x) | |
allChildVisited = False | |
break | |
if allChildVisited: | |
arr.pop(0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment