I have an tree like:
tree = [[[None,1,None],2,[None,3,None]],4,[None,6,[None,7,None]]]
The numbers represent the root of each node, the none represent the children that have no value.
For example, the main root is 4 and [[None,1,None],2,[None,3,None]] is the sub tree on the left and this [None,6,[None,7,None]] is he sub tree on the right. The principal root on the sub tree on the left is 2 etc etc...
And my problem is that I want to insert a value in this tree.
For example I want to add the value 5, this is that I want:
tree = [[[None, 1, None], 2, [None, 3, None]], 4, [[None, 5, None], 6, [None, 7, None]]]
My function takes two arguments, the tree and the integer to add, I need to use recursive function, for example this is what i started:
def insert(tree,int):
cur = tree
prev = None
while cur != None:
prev = cur
if int < cur[1]:
cur = cur[0]
else :
cur = cur[2]
Thanks in advance
intis not recommended as a variable name.