-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Organising information: trees", exercise 2 #32
Labels
Comments
def test_breadth_first_visit(root_node, expected):
if expected == breadth_first_visit(root_node):
return True
else:
return False
def breadth_first_visit(root_node):
output_list = []
queue = []
queue.append(root_node)
while queue != []:
output_list.append(queue[0])
queue.extend(queue[0].children)
queue.pop(0)
return output_list
elizabeth = Node("elizabeth")
charles = Node("charles", elizabeth)
anne = Node("anne", elizabeth)
william = Node("william", charles)
harry = Node("harry", charles)
george = Node("george", william)
charlotte = Node("charlotte", william)
louis = Node("louis", william)
archie = Node("archie", harry)
royals = [elizabeth,charles,anne,william,harry,george,charlotte,louis,archie]
print(test_breadth_first_visit(elizabeth, royals)) |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write the pure iterative version of the function defined in the previous exercise in Python.
The text was updated successfully, but these errors were encountered: