forked from DreamCats/java-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT57.java
More file actions
32 lines (31 loc) · 881 Bytes
/
T57.java
File metadata and controls
32 lines (31 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package web; /**
* @program LeetNiu
* @description: 二叉树的下一个结点
* @author: mf
* @create: 2020/01/16 14:22
*/
/**
* 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回。
* 注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。
*/
public class T57 {
public TreeLinkNode GetNext(TreeLinkNode pNode) {
if (null == pNode) {
return null;
}
if (null != pNode.right) {
pNode = pNode.right;
while (null != pNode.left) {
pNode = pNode.left;
}
return pNode;
}
while (null != pNode.next) {
if (pNode.next.left == pNode) {
return pNode.next;
}
pNode = pNode.next;
}
return null;
}
}