树遍历的变形

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */


struct TreeNode* convertBiNode(struct TreeNode* root){
    if(!root) return NULL;
    if(!root->left&&!root->right) return root;
    struct TreeNode* temp=convertBiNode(root->left);
    root->left=NULL;
    if(temp){
        struct TreeNode* a=temp;
        while(a && a->right) a=a->right;
        a->right=root;
    }
    struct TreeNode* t=convertBiNode(root->right);
    root->right=t;
    if(t) t->left=NULL;
    if(!temp) return root;
    return temp;
}

结果: