|
:) Use a linked list to do a hierarchical search.
On the first level, throw the root into the linked list.
In the second layer, find the L and R children of the root and replace the root in the linked list.
In the third layer, find the child nodes of the root L and R child nodes and replace them in the linked list.
In this recursion, if a node has no children, it is deleted, otherwise it is replaced by its own children. Keep child nodes in order from left to right.
This way to the last level, the last child node is what you are looking for.
Of course, when it is implemented, it is necessary to traverse one layer before deleting the previous one. :) |
|