mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
17 lines
604 B
Python
17 lines
604 B
Python
def in_order_traversal(node, visit_func):
|
|
if node is not None:
|
|
in_order_traversal(node.left, visit_func)
|
|
visit_func(node.data)
|
|
in_order_traversal(node.right, visit_func)
|
|
|
|
def pre_order_traversal(node, visit_func):
|
|
if node is not None:
|
|
visit_func(node.data)
|
|
pre_order_traversal(node.left, visit_func)
|
|
pre_order_traversal(node.right, visit_func)
|
|
|
|
def post_order_traversal(node, visit_func):
|
|
if node is not None:
|
|
post_order_traversal(node.left, visit_func)
|
|
post_order_traversal(node.right, visit_func)
|
|
visit_func(node.data) |