#!/usr/bin/python
#© Andreev Alexander (aka Carzil) 2011
class Node(object):
def __init__(self, key, left, right):
self.key = key
self.left = left
self.right = right
def set_value(self, val):
self.key = val
class Tree(object):
def __init__(self):
self.root = None
def add_key(self, val):
if self.root == None:
self.root = Node(val, None, None)
return
current = self.root
while current:
if val < current.key:
if current.left == None:
current.left = Node(val, None, None)
break
current = current.left
elif val > current.key:
if current.right == None:
current.right = Node(val, None, None)
break
current = current.right
else:
break
def insert(self, val):
self.add_key(val)
def inorder_(self):
if self.root == None:
return None
stack = []
node = self.root
while node or stack:
if node != None:
stack.append(node)
node = node.left
else:
node = stack.pop()
print(node.key, end=" ")
node = node.right
def inorder(self):
self.inorder_()
if __name__ == "__main__":
t = Tree()
for i in input().split():
if i == "0":
break
t.insert(int(i))
t.inorder()
#!/usr/bin/python
#© Andreev Alexander (aka Carzil) 2011
class Node(object):
def __init__(self, key, left, right):
self.key = key
self.left = left
self.right = right
def set_value(self, val):
self.key = val
class Tree(object):
def __init__(self):
self.root = None
def add_key(self, val):
if self.root == None:
self.root = Node(val, None, None)
current = self.root
while current:
if val < current.key:
if current.left == None:
current.left = Node(val, None, None)
break
current = current.left
elif val > current.key:
if current.right == None:
current.right = Node(val, None, None)
break
current = current.right
else:
break
def insert(self, val):
self.add_key(val)
def inorder_(self):
if self.root == None:
return None
stack = []
node = self.root
while node or stack:
if node != None:
stack.append(node)
node = node.left
else:
node = stack.pop()
print(node.key, end=" ")
node = node.right
def inorder(self):
self.inorder_()
t = Tree()
for i in input().split():
if i == "0":
break
t.insert(int(i))
t.inorder()