Skip to content

Commit

Permalink
added isinstance check
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaysharma096 committed Oct 13, 2016
1 parent ada433b commit 887f9e5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions traverals/binary_tree_traversals.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,35 @@ def build_tree():


def pre_order(node):
if not node:
if not isinstance(node, TreeNode) or not node:
print("Invalid input")
return
print(node.data, end=" ")
pre_order(node.left)
pre_order(node.right)


def in_order(node):
if not node:
if not isinstance(node, TreeNode) or not node:
print("Invalid input")
return
in_order(node.left)
print(node.data, end=" ")
in_order(node.right)


def post_order(node):
if not node:
if not isinstance(node, TreeNode) or not node:
print("Invalid input")
return
post_order(node.left)
post_order(node.right)
print(node.data, end=" ")


def level_order(node):
if not node:
if not isinstance(node, TreeNode) or not node:
print("Invalid input")
return
q = queue.Queue()
q.put(node)
Expand Down

0 comments on commit 887f9e5

Please sign in to comment.