elif tree.mark > item:
return Node(tree.mark,insert(tree.left,item),tree.right)
elif tree.mark < item:
return Node(tree.mark,tree.left,insert(tree.right,item))
else:
return tree
The last line is to make sure if tree.mark == item then you don't do anything and return as is.
3 conditions:
- If item is greater then insert right
- If item is smaller then insert left
- if item is same then don't insert and return as is.
If you take sample example and try, it would help.