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