Is this the right strategy to convert an in-level order binary tree to a doubly linked list?
- by Ankit Soni
So I recently came across this question - Make a function that converts a in-level-order binary tree into a doubly linked list. Apparently, it's a common interview question.
This is the strategy I had - Simply do a pre-order traversal of the tree, and instead of returning a node, return a list of nodes, in the order in which you traverse them. i.e return a list, and append the current node to the list at each point. For the base case, return the node itself when you are at a leaf.
so you would say
left = recursive_function(node.left)
right = recursive_function(node.right)
return(left.append(node.data)).append(right);`
Is this the right approach?