コード例 #1
0
        } // end constructor

        // insert TreeNode into Tree that contains nodes;
        // ignore duplicate values
        public void Insert(int insertValue)
        {
            if (insertValue < Data) // insert in left subtree
            {
                // insert new TreeNode
                if (LeftNode == null)
                {
                    LeftNode = new TreeNode(insertValue);
                }
                else // continue traversing left subtree
                {
                    LeftNode.Insert(insertValue);
                }
            } // end if
            else if (insertValue > Data) // insert in right subtree
            {
                // insert new TreeNode
                if (RightNode == null)
                {
                    RightNode = new TreeNode(insertValue);
                }
                else // continue traversing right subtree
                {
                    RightNode.Insert(insertValue);
                }
            } // end else if
        }     // end method Insert
コード例 #2
0
 // insert TreeNode into Tree that contains nodes;
 // ignore duplicate values
 public void Insert(T insertValue)
 {
     if (insertValue.CompareTo(Data) < 0) // insert in left subtree
     {
         // insert new TreeNode
         if (LeftNode == null)
         {
             LeftNode = new TreeNode <T>(insertValue);
         }
         else // continue traversing left subtree
         {
             LeftNode.Insert(insertValue);
         }
     }
     else if (insertValue.CompareTo(Data) > 0) // insert in right
     {
         // insert new TreeNode
         if (RightNode == null)
         {
             RightNode = new TreeNode <T>(insertValue);
         }
         else // continue traversing right subtree
         {
             RightNode.Insert(insertValue);
         }
     }
 }
コード例 #3
0
 public void Insert(int insertValue)
 {
     if (insertValue < Data)
     {
         if (LeftNode == null)
         {
             LeftNode = new TreeNode(insertValue);
         }
         else
         {
             LeftNode.Insert(insertValue);
         }
     }
     else if (insertValue > Data)
     {
         if (RightNode == null)
         {
             RightNode = new TreeNode(insertValue);
         }
         else
         {
             RightNode.Insert(insertValue);
         }
     }
 }
コード例 #4
0
 public void Insert(Movie myMovie)
 {
     //Lexographically, if the new node is equal to or greater than the current node
     if (string.Compare(myMovie.Title, this.Title) == 0 || string.Compare(myMovie.Title, this.Title) == 1)
     {
         if (RightNode == null)
         {
             RightNode = myMovie;
         }
         else
         {
             RightNode.Insert(myMovie);
         }
     }
     else
     {
         if (LeftNode == null)
         {
             LeftNode = myMovie;
         }
         else
         {
             LeftNode.Insert(myMovie);
         }
     }
 }
コード例 #5
0
 public void Insert(IComparable insertValue)
 {
     if (insertValue.CompareTo(Data) < 0)
     {
         if (LeftNode == null)
         {
             LeftNode = new TreeNode(insertValue);
         }
         else
         {
             LeftNode.Insert(insertValue);
         }
     }
     else if (insertValue.CompareTo(Data) > 0)
     {
         if (RightNode == null)
         {
             RightNode = new TreeNode(insertValue);
         }
         else
         {
             RightNode.Insert(insertValue);
         }
     }
 }
コード例 #6
0
        public void Insert(T data)
        {
            var compared = data.CompareTo(Element);

            if (compared < 0)
            {
                if (LeftNode != null)
                {
                    LeftNode.Insert(data);
                }
                else
                {
                    LeftNode = new Node <T>(data);
                }
            }
            else if (compared > 0)
            {
                if (RightNode != null)
                {
                    RightNode.Insert(data);
                }
                else
                {
                    RightNode = new Node <T>(data);
                }
            }
        }
コード例 #7
0
 public void Insert(MarkGeometryPoint point)
 {
     if (Value == null)
     {
         Value = point;
     }
     else if (IsLesser(Origin, point, Value))
     {
         if (LeftNode == null)
         {
             LeftNode = new IntersectionsBinaryTree(Origin, point);
         }
         else
         {
             LeftNode.Insert(point);
         }
     }
     else
     {
         if (RightNode == null)
         {
             RightNode = new IntersectionsBinaryTree(Origin, point);
         }
         else
         {
             RightNode.Insert(point);
         }
     }
 }
コード例 #8
0
 public void Insert(D data)
 {
     if (data.CompareTo(Data) < 0)
     {
         if (null == LeftNode)
         {
             LeftNode = new Node <D>(data);
         }
         else
         {
             LeftNode.Insert(data);
         }
     }
     else
     {
         if (null == RightNode)
         {
             RightNode = new Node <D>(data);
         }
         else
         {
             RightNode.Insert(data);
         }
     }
 }
コード例 #9
0
        } // end constructor

        // insert TreeNode into Tree that contains nodes;
        // ignore duplicate values
        public void Insert(IComparable insertValue)
        {
            if (insertValue.CompareTo(Data) < 0) // insert in left subtree
            {
                // insert new TreeNode
                if (LeftNode == null)
                {
                    LeftNode = new TreeNode(insertValue);
                }
                else // continue traversing left subtree
                {
                    LeftNode.Insert(insertValue);
                }
            } // end if
            else if (insertValue.CompareTo(Data) > 0)  // insert in right
            {
                // insert new TreeNode
                if (RightNode == null)
                {
                    RightNode = new TreeNode(insertValue);
                }
                else // continue traversing right subtree
                {
                    RightNode.Insert(insertValue);
                }
            } // end else if
        }     // end method Insert
コード例 #10
0
 public void Insert(int value)
 {
     //if the value passed is greater than or equal to the data then insert right node
     if (value >= Data)
     {
         //if rightNode is null, instantiate a new rightNode
         if (RightNode == null)
         {
             RightNode = new TreeNode(value);
         }
         //if not null, recursively call insert on the rightNode
         else
         {
             RightNode.Insert(value);
         }
     }
     else
     {
         //if the value passed is less than the data, insert left node
         //if leftNode is null, instantiate one
         if (LeftNode == null)
         {
             LeftNode = new TreeNode(value);
         }
         //if not null, recursively call Insert on the leftNode
         else
         {
             LeftNode.Insert(value);
         }
     }
 }
コード例 #11
0
ファイル: UnionNode.cs プロジェクト: laszlo-kiss/Dataphor
        protected void InternalInsertLeft(Program program, IRow oldRow, IRow newRow, BitArray valueFlags, bool uncheckedValue)
        {
            switch (PropagateInsertLeft)
            {
            case PropagateAction.True:
                LeftNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                break;

            case PropagateAction.Ensure:
            case PropagateAction.Ignore:
                using (Row leftRow = new Row(program.ValueManager, LeftNode.DataType.RowType))
                {
                    newRow.CopyTo(leftRow);
                    using (IRow currentRow = LeftNode.Select(program, leftRow))
                    {
                        if (currentRow != null)
                        {
                            if (PropagateInsertLeft == PropagateAction.Ensure)
                            {
                                LeftNode.Update(program, currentRow, newRow, valueFlags, false, uncheckedValue);
                            }
                        }
                        else
                        {
                            LeftNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                        }
                    }
                }
                break;
            }
        }
コード例 #12
0
        public void Insert(int value, INode <int> parentNode)
        {
            if (value == 0 || value == this.Value)
            {
                return;
            }

            if (value < this.Value)
            {
                if (LeftNode == null)
                {
                    LeftNode = new Node {
                        Value = value
                    };
                    this.ParentNode = parentNode;
                }
                else
                {
                    LeftNode.Insert(value, this);
                }
            }
            else
            {
                if (RightNode == null)
                {
                    RightNode = new Node {
                        Value = value
                    };
                    this.ParentNode = parentNode;
                }
                else
                {
                    RightNode.Insert(value, this);
                }
            }
        }
コード例 #13
0
ファイル: UnionNode.cs プロジェクト: laszlo-kiss/Dataphor
        protected override void InternalExecuteUpdate(Program program, IRow oldRow, IRow newRow, BitArray valueFlags, bool checkConcurrency, bool uncheckedValue)
        {
            if (PropagateUpdateLeft && PropagateUpdateRight && EnforcePredicate)
            {
                // Attempt to update the row in the left node
                try
                {
                    if (PropagateUpdateLeft)
                    {
                        using (IRow leftRow = LeftNode.FullSelect(program, oldRow))
                        {
                            if (leftRow != null)
                            {
                                LeftNode.Delete(program, oldRow, checkConcurrency, uncheckedValue);
                            }
                        }

                        LeftNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                    }
                }
                catch (DataphorException exception)
                {
                    if ((exception.Severity == ErrorSeverity.User) || (exception.Severity == ErrorSeverity.Application))
                    {
                        if (PropagateUpdateRight)
                        {
                            using (IRow rightRow = RightNode.FullSelect(program, oldRow))
                            {
                                if (rightRow != null)
                                {
                                    RightNode.Delete(program, oldRow, checkConcurrency, uncheckedValue);
                                }
                            }

                            RightNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                        }
                        return;
                    }
                    throw;
                }

                // Attempt to update the row in the right node
                try
                {
                    if (PropagateUpdateRight)
                    {
                        using (IRow rightRow = RightNode.FullSelect(program, oldRow))
                        {
                            if (rightRow != null)
                            {
                                RightNode.Delete(program, oldRow, checkConcurrency, uncheckedValue);
                            }
                        }

                        RightNode.Insert(program, oldRow, newRow, valueFlags, uncheckedValue);
                    }
                }
                catch (DataphorException exception)
                {
                    if ((exception.Severity != ErrorSeverity.User) && (exception.Severity != ErrorSeverity.Application))
                    {
                        throw;
                    }
                }
            }
            else
            {
                if (PropagateUpdateLeft)
                {
                    LeftNode.Update(program, oldRow, newRow, valueFlags, checkConcurrency, uncheckedValue);
                }

                if (PropagateUpdateRight)
                {
                    RightNode.Update(program, oldRow, newRow, valueFlags, checkConcurrency, uncheckedValue);
                }
            }
        }