public class Solution {
public TreeLinkNode GetNext(TreeLinkNode pNode) {
if (pNode == null) {
return null;
}
TreeLinkNode pNext = null;
if (pNode.right != null) {
TreeLinkNode mRight = pNode.right;
while (mRight.left != null) {
mRight = mRight.left;
}
pNext = mRight;
} else if (pNode.next != null) {
TreeLinkNode current = pNode;
TreeLinkNode parent = pNode.next;
while (parent != null && current == parent.right) {
current = parent;
parent = parent.next;
}
pNext = parent;
}
return pNext;
}
}
剑指Offer 二叉树的下一个结点
最新推荐文章于 2024-08-19 16:01:20 发布