interactive-coding-challenges/graphs_trees/bst/dfs.py
2015-08-01 17:44:14 -04:00

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)