static SuccessorTreeNode GetMin(SuccessorTreeNode node) { while (node.left != null) { node = node.left; } return(node); }
static SuccessorTreeNode FindSuccessorFromParent(SuccessorTreeNode node) { if (node.right != null) { return(GetMin(node.right)); } SuccessorTreeNode parent = node.parent; while (parent != null && parent.right == node) { node = parent; parent = parent.parent; } return(parent); }
static SuccessorTreeNode FindSuccessforFromRoot(SuccessorTreeNode root, SuccessorTreeNode node) { if (node.right != null) { return(GetMin(node.right)); } SuccessorTreeNode successor = null; while (root != null) { if ((int)node.val <= (int)root.val) { successor = root; root = root.left; } else if ((int)node.val > (int)root.val) { root = root.right; } } return(successor); }
public SuccessorTreeNode(object data) { val = data; left = right = parent; }