class BinarySearchTree:
def init(self):
self.root = None
def create(self, val):
if self.root == None:
self.root = Node(val)
else:
current = self.root
while True:
if val < current.info:
if current.left:
current = current.left
else:
current.left = Node(val)
break
elif val > current.info:
if current.right:
current = current.right
else:
current.right = Node(val)
break
else:
break
"""
Node is defined as
self.left (the left child of the node)
self.right (the right child of the node)
self.info (the value of the node)
"""
def levelOrder(root):
Write code Here
queue = [root]
s = ""
while queue :
t = queue.pop(0)
s = s + " " + str(t.info)
if t.left is not None :
queue.append(t.left)
if t.right is not None :
queue.append(t.right)
print(s.strip())
문제 풀이
class BinarySearchTree: def init(self): self.root = None
""" Node is defined as self.left (the left child of the node) self.right (the right child of the node) self.info (the value of the node) """ def levelOrder(root):
Write code Here