[Binary Tree Algorithm] Let all tree leaf nodes together into a single linked list, so as the next pointer rchild

// make the tree all leaf nodes together into a single linked list, so as the next pointer rchild 
LNode head * = null , pre * = null ; // global variable 
LNode the InOrder * (BTNode * T) {
     IF (! T = null ) { 
        the InOrder (T -> lchild);
         IF (T-> lchild == null && T-> rchild == null ) {
             IF (pre == null ) { 
                pre = T; 
                head = T; 
            } the else { 
                pre -> rchild =  T;
                pre=T;
            }
        }
        InOrder(T->rchild);
        pre->rchild=null;
    }
    return head;
}

Guess you like

Origin www.cnblogs.com/zzuuoo666/p/12083163.html