public class Solution { public TreeLinkNode GetNext(TreeLinkNode pNode) { return pNode.right == null ? toUp(pNode) : toRight(pNode.right); } TreeLinkNode toRight(TreeLinkNode node) { if (node.left == null) return node; return toRight(node.left); } TreeLinkNode toUp(TreeLinkNode node) { if (node.next == null) return null; if (node == node.next.left) return node.next; return toUp(node.next); } }