输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。
public class Test26 {
TreeNode head=null;
TreeNode tail=null;
public TreeNode Convert(TreeNode pRootOfTree) {
if(pRootOfTree==null){
return null;
}
Convert(pRootOfTree.left);
if(tail==null){
head=pRootOfTree;
tail=pRootOfTree;
}else{
tail.right=pRootOfTree;
pRootOfTree.left=tail;
tail=pRootOfTree;
}
Convert(pRootOfTree.right);
return head;
}
}