I could not figure out how to write the first function during the lab. The TA said that we should construct a helper function which finds the first LLNode and the last.
I suppose that it should work as taking in the left branch of the node and finding the first node of the in-order traversal and the last node. The reason for that is what we do is that we take the root node of the tree, represent it as an LLNode, append the traversal of the right branch to it, and append itself to the end of the traversal of its left branch. The last step is the most complicated step since we do not know to which LLNode we should append the root LLNode to, unless we can get access to the last node of the left branch.
Then the entire code should be like:
make an LLNode with the root value given as its item
use the helper to find the first node and last node of the left branch
make this root LLNode the link of the last node of left branch, and make the first node of traversal of the right node the link of itself
Then the rest of the work can be done by recursion.
Revision:
After the term test I found that I should have worked harder to understand this lab task better, because it seems that we needed a similar helper for the function we're writing on the test... But I had no idea on how exactly the helper should look like... My regrets:( and especially for that unlike my buddies I do need the 60% course grade in order to get into the program since I'm in PMS... I did assume that the test would not be "as hard as the lab is" so I did not really pay too much effort on it.
No comments:
Post a Comment