二叉搜索树与双向链表

题目:输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。

思路:中序遍历。。。指针的调节比较难理解。。。

/**
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
 TreeNode head=null;
    TreeNode realHead=null;
    public TreeNode Convert(TreeNode pRootOfTree) {
       link(pRootOfTree);
        return realHead;
    }
    void link(TreeNode root){
       if(root==null) return;
        link(root.left);
        if(head==null){
            head=root;
            realHead=root;
        }else{
         head.right=root;
         root.left=head;
         head=root;
        } 
        link(root.right);
    }