Binary turn doubly linked list

Enter a binary search tree, the binary search tree converted into a doubly linked list sorted. Requirements can not create any new node, point to only adjust the tree node pointer.

public class Solution {
    private TreeNode leftHead=null;
    private TreeNode rightHead=null;
    public TreeNode Convert(TreeNode pRootOfTree) {
        if(pRootOfTree==null)
        {
            return null;
        }
        Convert(pRootOfTree.left);
        if(rightHead==null){
            leftHead=rightHead=pRootOfTree;
        }else{
            rightHead.right=pRootOfTree;
            pRootOfTree.left=rightHead;
            rightHead=pRootOfTree;
        }
        Convert(pRootOfTree.right);
        return leftHead;
    }
   
}

Preorder

Guess you like

Origin blog.csdn.net/qq_30035749/article/details/90035440