public Boolean HasDescendent(GeneralTreeNode <NodeValueType> node) { Boolean result = HasChild(node); for (Int32 i = 0; !result && i < ChildrenCount; ++i) { result = Children[i].HasDescendent(node); } return(result); }
public void InsertAfter(GeneralTreeNode <NodeValueType> reference, GeneralTreeNode <NodeValueType> node) { if (reference == null) { throw new ArgumentNullException("reference", "Cannot insert before a null reference node."); } else if (node == null) { throw new ArgumentNullException("node", "Cannot insert a null node."); } else { reference.Children.Add(node); } }
public void InsertRoot(GeneralTreeNode <NodeValueType> node) { if (node != null) { if (!IsEmpty) { node.Children.Add(Root); } Root = node; } else { throw new ArgumentNullException("node", "Cannot insert a null root."); } }
public Boolean HasAncestor(GeneralTreeNode <NodeValueType> node) { Boolean result = false; if (HasParent) { result = Parent.Equals(node); if (!result) { result = Parent.HasAncestor(node); } } return(result); }
public void Remove(GeneralTreeNode <NodeValueType> node, Boolean orphanChildren = false) { if (node == null) { throw new ArgumentNullException("node", "Cannot remove a null node."); } else if (!IsEmpty) { GeneralTreeNode <NodeValueType> presentNode = Search(node); if (presentNode != null) { presentNode.Parent.Children.Remove(presentNode); if (orphanChildren) { node.Clear(); } } } }
public GeneralTreeNode <NodeValueType> Search(NodeValueType value, IEnumerator <GeneralTreeNode <NodeValueType> > enumerator) { if (enumerator == null) { throw new ArgumentNullException("enumerator", "Node enumerator cannot be null."); } else { enumerator.Reset(); GeneralTreeNode <NodeValueType> result = null; while (result == null && enumerator.MoveNext()) { if (enumerator.Current == null && value == null || enumerator.Current.Equals(value)) { result = enumerator.Current; } } return(result); } }
public void InsertBefore(GeneralTreeNode <NodeValueType> reference, GeneralTreeNode <NodeValueType> node) { if (reference == null) { throw new ArgumentNullException("reference", "Cannot insert before a null reference node."); } else if (node == null) { throw new ArgumentNullException("node", "Cannot insert a null node."); } else { if (reference.IsRoot) { InsertRoot(node); } else { reference.Parent.Children.Add(node); reference.Parent.Children.Remove(reference); node.Children.Add(reference); } } }
public GeneralTree(GeneralTreeNode <NodeValueType> root) { Root = root; }
protected GeneralTreeNode <NodeValueType> Search(GeneralTreeNode <NodeValueType> node) { return(Search(node.Value)); }
public void InsertAfter(GeneralTreeNode <NodeValueType> reference, NodeValueType value) { InsertAfter(reference, new GeneralTreeNode <NodeValueType>(value)); }
public Boolean HasChild(GeneralTreeNode <NodeValueType> node) { return(Children.Contains(node)); }
/// <remarks>Only the Value is checked for equality to prevent a complete traversal of the tree.</remarks> public Boolean Equals(GeneralTreeNode <NodeValueType> other) { return(Value.Equals(other.Value)); }