public BinaryTreeNodeWithParent Find(BinaryTreeNodeWithParent node) { if (node != null) { BinaryTreeNodeWithParent p; if (node.Parent == null || node.Right != null) { p = LeftMostChild(node.Right); } else { while ((p = node.Parent) != null) { if (p.Left == node) { break; } node = p; } } return p; } return null; }
public void BuildTree() { root = new BinaryTreeNodeWithParent(7); root.Left = new BinaryTreeNodeWithParent(3); root.Left.Left = new BinaryTreeNodeWithParent(2); root.Left.Right = new BinaryTreeNodeWithParent(5); root.Right = new BinaryTreeNodeWithParent(11); root.Right.Right = new BinaryTreeNodeWithParent(17); root.Right.Right.Left = new BinaryTreeNodeWithParent(13); }
private BinaryTreeNodeWithParent LeftMostChild(BinaryTreeNodeWithParent node) { if (node == null) { return null; } while (node.Left != null) { node = node.Left; } return node; }