i want to create a binary tree program but the final result returns unwanted result .i tried to compare the values in it but i think it's the wrong way to get the right result.
the binary tree should be show the output :
15 25 20 30 10 7 13 14 6 9 11 17 27 32 23
root node : 6
this my program when i was create:
class Node:
def __init__(self, value, left=None, right=None):
self.left=None
self.value=value
self.right=None
def insert(self, value):
if self.value:
if value < self.value:
if self.left is None:
self.left = Node(value)
else:
self.left.insert(value)
elif value > self.value:
if self.right is None:
self.right = Node(value)
else:
self.right.insert(value)
else:
self.value = value
def printTree(self):
if self.left:
self.left.printTree()
print( self.value),
if self.right:
self.right.printTree()
root=Node(6)
root.insert(15)
root.insert(25)
root.insert(20)
root.insert(30)
root.insert(10)
root.insert(7)
root.insert(13)
root.insert(14)
root.insert(9)
root.insert(11)
root.insert(17)
root.insert(27)
root.insert(32)
root.insert(23)
root.printTree()
i need your opinion to fix this program.