예제 #1
0
        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);
        }
예제 #2
0
 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);
     }
 }
예제 #3
0
        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.");
            }
        }
예제 #4
0
        public Boolean HasAncestor(GeneralTreeNode <NodeValueType> node)
        {
            Boolean result = false;

            if (HasParent)
            {
                result = Parent.Equals(node);

                if (!result)
                {
                    result = Parent.HasAncestor(node);
                }
            }

            return(result);
        }
예제 #5
0
        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();
                    }
                }
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
 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);
         }
     }
 }
예제 #8
0
 public GeneralTree(GeneralTreeNode <NodeValueType> root)
 {
     Root = root;
 }
예제 #9
0
 protected GeneralTreeNode <NodeValueType> Search(GeneralTreeNode <NodeValueType> node)
 {
     return(Search(node.Value));
 }
예제 #10
0
 public void InsertAfter(GeneralTreeNode <NodeValueType> reference, NodeValueType value)
 {
     InsertAfter(reference, new GeneralTreeNode <NodeValueType>(value));
 }
예제 #11
0
 public Boolean HasChild(GeneralTreeNode <NodeValueType> node)
 {
     return(Children.Contains(node));
 }
예제 #12
0
 /// <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));
 }