binnary tree code example
Example 1: binary tree
class Node:
def __init__(self,key):
self.left = None
self.right = None
self.val = key
root = Node(1)
root.left = Node(2);
root.right = Node(3);
root.left.left = Node(4);
Example 2: tree data structure
If root is NULL
then create root node
return
If root exists then
compare the data with node.data
while until insertion position is located
If data is greater than node.data
goto right subtree
else
goto left subtree
endwhile
insert data
end If