I ran into an interesting problem called the Big Tree List Problem. The problem is this:
In an ordered binary tree, each node contains one data element and βsmallβ and βlargeβ pointers to subtrees. All nodes in the "small" subtree are less than or equal to the data in the parent node. All nodes in the "large" subtree are larger than the parent node. And the circular double list consists of the previous and next pointers.
The task is to take an ordered binary tree and rearrange the internal pointers to make a circular double-linked list from it. The "small" pointer should play the role of "previous", and the "big" pointer should play the role of "next". The list should be organized so that the nodes are in ascending order. I have to write a recursive function and return a pointer to a new list.
The operation must be performed in O (n) time.
I understand that recursion will go through the tree, but how to change small and large subtrees to lists recursively, I also need to add these lists along with the parent node.
How can I approach the problem? .. I just need a guide to solve the problem!
source share