/// <summary> /// Removes the child element. /// </summary> /// <param name="child">The child element to be removed.</param> /// <returns>True if the child parameter was in fact a child of this node, false otherwise.</returns> public bool RemoveChild(OrderedTree <T> child) { if (children.Contains(child)) { children.Remove(child); child.Parent = null; return(true); } return(false); }
/// <summary> /// Checks if the given iteration over this tree contains the provided tree. /// </summary> /// <param name="tree">The potentially contained tree.</param> /// <param name="iter">The iteration applied.</param> /// <returns></returns> public bool Has(OrderedTree <T> tree, Func <OrderedTree <T>, IEnumerable <OrderedTree <T> > > iter = null) { if (iter == null) { iter = TreeIter.BreadthFirst; } return(iter(this).Contains(tree)); }
private OrderedTree(T val, OrderedTree <T> parent) { Value = val; Parent = parent; parent.children.Add(this); }
/// <summary> /// Creates a new tree with this instance at its root. Each instance is a node of the tree. /// </summary> /// <param name="val">The value of the node associated with the tree.</param> public OrderedTree(T val) { Value = val; Parent = null; }
/// <summary> /// Checks if the child parameter is a child of this tree node. /// </summary> /// <param name="child">The potential child node.</param> /// <returns></returns> public bool HasChild(OrderedTree <T> child) => children.Contains(child);