treeToTuple Inputs

i wrote the code for the tree to tuple method, but i don’t understand how to pass the inputs
Can anyone help
def treeToTuple(node):
if node.left != None and node.right != None:
nodeR = treeToTuple(node.right)
nodeL = treeToTuple(node.left)
nodeK = (nodeL,node,nodeR)
elif node.left != None and node.right == None:
nodeL = treeToTuple(node.left)
nodeK = (nodeL,node,None)
elif node.left == None and node.right != None:
nodeR = treeToTuple(node.right)
nodeK = (None,node,nodeR)
else:
nodeK = node.key
return nodeK

1 Like

I think There are some bugs in your code…
Do you want me Correct them and tell you…or will you figure out them yourself ??

Moreover…I quiet didn’t understand your question…

If you are asking what parameter should be passed…then it is the HEAD node that is to be passed for eg, for the following tree…
image

The Head Node (1) will be given as parameter…

and the output will be
(3, 1, 7)

Hope it Helps…

naa i just wanted to know the input format
i’ll try to figure out the bugs meself
if i won’t be able to then i’ll ask

1 Like

That’s The spirit… :sunglasses: :sunglasses: :sunglasses:

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)