/// <summary> /// Удаляет ветку, которой принадлежит "лист". /// </summary> public void RemoveBrenchWithLeaf(TreeElement <T> leaf) { if (leaf.HasChildren) { throw new Exception("Элемент не является крайним"); } if (!_elements.Contains(leaf)) { throw new Exception("Нет такого элемента"); } var parent = leaf.Parent; var elementToDelete = leaf; while (parent.Children.Count == 1 && parent != Root) { elementToDelete = parent; parent = parent.Parent; } RemoveBrenchAfter(elementToDelete); }
internal void RemoveChild(TreeElement <T> child) { _children.Remove(child); child.Parent = null; }
internal TreeElement(T content, TreeElement <T> parent) { Content = content; Parent = parent; _children = new List <TreeElement <T> >(); }
public Tree() { Root = new TreeElement <T>(); _elements = new HashSet <TreeElement <T> >(); }