代码：

```package Algorithms.tree;

public class SuccessorNode {

public static class Node {
public int value;
public Node left;
public Node right;
public Node parent;

public Node(int data) {
this.value = data;
}
}

//求某一个节点的后继节点
public static Node getSuccessorNode(Node node) {
if (node == null) {
return node;
}
if (node.right != null) { //有右子树
return getLeftMost(node.right);
} else { //无右子树
Node parent = node.parent; //找到其父节点
//while循环找当前节点是其父节点的左子树
while (parent != null && parent.left != node) {  //当前节点是其父节点的右子树
node = parent; //node往上走到parent的位置
parent = node.parent; //parent来到node父节点的位置
}
//当前节点是其父节点的左子树  或者  父节点为空（node是整棵树最右节点时）时退出while循环
return parent; //退出循环说明找到了后继节点
}
}

//返回一个节点子树中最左的Node
public static Node getLeftMost(Node node) {
if (node == null) {
return node;
}
while (node.left != null) {
node = node.left;
}
return node;
}

public static void main(String[] args) {

System.out.println(test.value + " next: " + getSuccessorNode(test).value);
System.out.println(test.value + " next: " + getSuccessorNode(test).value);
System.out.println(test.value + " next: " + getSuccessorNode(test).value);
System.out.println(test.value + " next: " + getSuccessorNode(test).value);
System.out.println(test.value + " next: " + getSuccessorNode(test).value);
System.out.println(test.value + " next: " + getSuccessorNode(test).value);
System.out.println(test.value + " next: " + getSuccessorNode(test).value);
System.out.println(test.value + " next: " + getSuccessorNode(test).value);
System.out.println(test.value + " next: " + getSuccessorNode(test).value);
test = head.right.right; // 10's next is null
System.out.println(test.value + " next: " + getSuccessorNode(test));
}
}
//中序遍历结果：1,2,3,4,5,6,7,8,9
/**
* 1 next: 2
* 2 next: 3
* 3 next: 4
* 4 next: 5
* 5 next: 6
* 6 next: 7
* 7 next: 8
* 8 next: 9
* 9 next: 10
* 10 next: null
*/```