private void SetLeftChild(BinaryTreeNode <T> target) { if (target is null) { RemoveLeftChild(); return; } if (target.CompareTo(this) > 0) { throw new Exception("Value of left child cannot be greater than value of node"); } var existingLeftChild = Neighbours.Cast <BinaryTreeNode <T> >().FirstOrDefault(n => n.IsLeftChild); if (existingLeftChild != null) { RemoveLeftChild(); } target.IsLeftChild = true; target.IsRightChild = false; Neighbours.Add(target); _leftChild = target; }
public void RemoveRightChild() { var rightChild = Neighbours.Cast <BinaryTreeNode <T> >().SingleOrDefault(n => n.IsRightChild); if (rightChild != null) { rightChild.IsRightChild = false; Neighbours.Remove(rightChild); _rightChild = null; } }
public void RemoveLeftChild() { var leftChild = Neighbours.Cast <BinaryTreeNode <T> >().SingleOrDefault(n => n.IsLeftChild); if (leftChild != null) { leftChild.IsLeftChild = false; Neighbours.Remove(leftChild); _leftChild = null; } }