There's a nice recursive insight you can use for solving this problem. I'll let you work out the details about how to actually implement this in code, since I don't know how you have the tree represented, but here's the core idea.
First, it's really easy to convert an empty tree into LC/RS format: it comes back as the empty tree.
On the other hand, suppose you have a nonempty tree. Start off by converting each of its children into LC/RS format (recursively). For example, given this tree:
A
/ | \
B C D
/ | \ |
E F G H
/ \
I J
You'd start off by recursively converting each child to LC/RS, giving back these three trees:
B C D
/ /
E H
\
F
/ \
I G
\
J
These trees currently are free-floating and not linked to one another. But since you know that they're siblings, you'll want to make C the right child of B and D the right child of C. That's essentially a linked list traversal. Here's what things should look like when you're done:
B
/ \
E C
\ \
F D
/ \ /
I G H
\
J
Once you've done that, all that's left to do is make B the left child of A, as shown here:
A
/
B
/ \
E C
\ \
F D
/ \ /
I G H
\
J
To recap, the logic goes like this:
- If the tree to convert is empty, return an empty tree.
- Otherwise:
- Recursively convert each of the children of the root node into LC/RS format.
- Iterate across those trees, assigning right child links to link the trees together.
- Assign A's left child pointer to point to the resulting tree (or to null if it has no children).
I'll leave the C++ details to you to fill in. If you've made an attempt to solve this problem and are running into trouble, feel free to post a follow-up question detailing the code that you've written so far along with a specific test case that's failing or the specific compiler errors you're encountering. Good luck!