public TreeLinkNode GetNext(TreeLinkNode pNode)
{
if(pNode==null)
return null;
TreeLinkNode right = pNode.right;//右子树
TreeLinkNode result = null;
//节点有右子树,则为右子树总最左边的节点
if(right!=null){
while(right.left!=null)
right = right.left;
result = right;
}else{//没有右子树
TreeLinkNode f = pNode.next;//父节点
if(f==null);//根节点
if(f!=null){//存在父节点
TreeLinkNode fLeft = f.left;
if(fLeft==pNode){//在左子树上
result= f;
}else{//在右子树上
//找到根节点
TreeLinkNode root=f.next;
while(root.next!=null){
f = f.next;
root=f.next;
}
TreeLinkNode rootleft = root.left;
if(f==rootleft)
result = root;
}
}
}
return result;
}