mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
added isinstance check
This commit is contained in:
parent
ada433b452
commit
887f9e5b01
|
@ -40,7 +40,8 @@ def build_tree():
|
||||||
|
|
||||||
|
|
||||||
def pre_order(node):
|
def pre_order(node):
|
||||||
if not node:
|
if not isinstance(node, TreeNode) or not node:
|
||||||
|
print("Invalid input")
|
||||||
return
|
return
|
||||||
print(node.data, end=" ")
|
print(node.data, end=" ")
|
||||||
pre_order(node.left)
|
pre_order(node.left)
|
||||||
|
@ -48,7 +49,8 @@ def pre_order(node):
|
||||||
|
|
||||||
|
|
||||||
def in_order(node):
|
def in_order(node):
|
||||||
if not node:
|
if not isinstance(node, TreeNode) or not node:
|
||||||
|
print("Invalid input")
|
||||||
return
|
return
|
||||||
in_order(node.left)
|
in_order(node.left)
|
||||||
print(node.data, end=" ")
|
print(node.data, end=" ")
|
||||||
|
@ -56,7 +58,8 @@ def in_order(node):
|
||||||
|
|
||||||
|
|
||||||
def post_order(node):
|
def post_order(node):
|
||||||
if not node:
|
if not isinstance(node, TreeNode) or not node:
|
||||||
|
print("Invalid input")
|
||||||
return
|
return
|
||||||
post_order(node.left)
|
post_order(node.left)
|
||||||
post_order(node.right)
|
post_order(node.right)
|
||||||
|
@ -64,7 +67,8 @@ def post_order(node):
|
||||||
|
|
||||||
|
|
||||||
def level_order(node):
|
def level_order(node):
|
||||||
if not node:
|
if not isinstance(node, TreeNode) or not node:
|
||||||
|
print("Invalid input")
|
||||||
return
|
return
|
||||||
q = queue.Queue()
|
q = queue.Queue()
|
||||||
q.put(node)
|
q.put(node)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user