Given a Binary Tree, extract all leaves of it in a Doubly Linked List (DLL). Note that the DLL need to be created in-place. Assume that the node structure of DLL and Binary Tree is same, only the meaning of left and right pointers are different. In DLL, left means previous pointer and right means next pointer.
The first step is to be able to print the leaves. It is simple, you can do a in-order traversal and put a condition (isLeaf) before printing. When you understand this, the rest is making the program work with the boundary conditions. To trim the original tree, we need the reference to the parent pointer in the recursive call.