原题链接https://www.nowcoder.com/practice/9023a0c988684a53960365b889ceaf5e?tpId=265&&tqId=39212&rp=1&ru=/ta/coding-interviews-all&qru=/ta/coding-interviews-all/question-ranking
public TreeLinkNode GetNext(TreeLinkNode pNode) {
TreeLinkNode result = null;
if(pNode.right!=null) { //有右子树
result=pNode.right;
while(result.left!=null) {
result=result.left;
}
}
else { //没有右子树
if(pNode.next==null)
return result;
result=pNode.next;
if(result.left!=pNode) { //不是左子节点
while(result!=result.next.left) {
result=result.next;
if(result.next==null)
return null;
}
result=result.next;
}
}
return result;