I am working on a school assignment. This manly consists of a method that takes as input binary tree and returns a double-threaded tree. For example (if left child = null, then the left child will be associated with the previous parent inorder, and if the correct child = null, it will refer to its suorder code. Now I have an idea for implementing ...
I repeat recursively through the original BINARY tree and store the traversal in order in the array. Now, since my teacher implementation requires flow trees to be another binary class. I have to go through the binary tree again and convert each node from binaryNode to threadedNode, thus having at the end a "duplicate" of the original BinaryTree, but as a type of Threadedtree. After that, I go through this threadedTree again, and whenever I see a zero left or right child, I go to the inorder arraylist and find the threads.
Now, as you may have noticed, this is extremely inefficient, I essentially cross the tree 3 times. My professor stated that this can be done recursively with just one workaround, essentially converting to threadedNode and searching for threads at the same time. I tried several ways, but I can not find the one that works. Does anyone have any hint or somehow can I implement it? Thanks
This is the method indicated by the instructor.
public static <T> ThreadedNode<T> thread(BinaryNode<T> root) {
source share