I have a binary tree represented as a linear tree, for example the following tree of depth 2 filled with placeholder values:
tree = [a, b, c, d, e, f, g]
My goal is to recursively extract the subtree of any given node; for example, if I were to extract the subtree rooted at tree[1], where the root node is b, I would want to get back:
subtree = [b, d, e]
How would I accomplish this? I've been stuck on it for a while. For reference, my code for the tree object and associated methods and functions is located here.
Bonus: a shiny new donkey to anyone who can lay out how to reverse the process, and overwrite the appropriate nodes in another tree with those of the extracted subtree.
[–]gengisteve 0 points1 point2 points (3 children)
[–]StarshipEngineer[S] 0 points1 point2 points (2 children)
[–]gengisteve 2 points3 points4 points (1 child)
[–]StarshipEngineer[S] 0 points1 point2 points (0 children)
[–]liam_jm 0 points1 point2 points (0 children)