コード例 #1
0
 public void Add(T value)
 {
     if (value.Equals(Value))
     {
         if (RightNode != null)
         {
             RightNode = new Node <T>(value);
         }
         else
         {
             RightNode.Add(value);
         }
     }
     else
     {
         if (LeftNode != null)
         {
             LeftNode.Add(value);
         }
         else
         {
             LeftNode = new Node <T>(value);
         }
     }
 }
コード例 #2
0
ファイル: TreeNode.cs プロジェクト: mturaga/bst
        public bool IsBalanced()
        {
            int leftHeight  = 0;
            int rightHeight = 0;

            if (this.LeftNode != null)
            {
                leftHeight = this.LeftNode.Height();
            }

            if (this.RightNode != null)
            {
                rightHeight = this.RightNode.Height();
            }

            if (Math.Abs(leftHeight - rightHeight) > 1)
            {
                return(false);
            }


            bool isLeftBalanced = LeftNode != null?LeftNode.IsBalanced() : true;

            bool isRightBalanced = RightNode != null?RightNode.IsBalanced() : true;

            return(isLeftBalanced && isRightBalanced);
        }
コード例 #3
0
 protected override void InternalExecuteDelete(Program program, IRow row, bool checkConcurrency, bool uncheckedValue)
 {
     if (PropagateDeleteLeft)
     {
         LeftNode.Delete(program, row, checkConcurrency, uncheckedValue);
     }
 }
コード例 #4
0
        public void InOrderTraversal()
        {
            if (LeftNode != null)
            {
                LeftNode.InOrderTraversal();
            }

            //Then we print the root node
            Console.WriteLine("\nTitle: {0}", this.Title);
            Console.WriteLine("Staring: {0}", string.Join(", ", this.Starring));
            Console.WriteLine("Director: {0}", this.Director);
            Console.WriteLine("Genre: {0}", this.Genre);
            Console.WriteLine("Classification: {0}", this.Classification);
            Console.WriteLine("Duration: {0} minutes", this.Duration);
            Console.WriteLine("Release Date: {0}", this.ReleaseDate);
            Console.WriteLine("Copies That Exist: {0}", this.NumberOfCopiesThatExist);
            Console.WriteLine("Copies Available: {0}", this.NumberOfCopiesAvailable);
            Console.WriteLine("Times Borrowed: {0}\n", this.NumTimesBorrowed);

            //Then we go to the right node which will print itself as both its children are null
            if (RightNode != null)
            {
                RightNode.InOrderTraversal();
            }
        }
コード例 #5
0
ファイル: BipartiteMatching.cs プロジェクト: 15139288365/C5
            public BipartiteMatching(SCG.IEnumerable <Rec <TLeftLabel, TRightLabel> > graph)
            {
                HashDictionary <TRightLabel, RightNode>           rdict = new HashDictionary <TRightLabel, RightNode>();
                HashDictionary <TLeftLabel, HashSet <RightNode> > edges = new HashDictionary <TLeftLabel, HashSet <RightNode> >();
                HashSet <RightNode> newrnodes = new HashSet <RightNode>();

                foreach (Rec <TLeftLabel, TRightLabel> edge in graph)
                {
                    var x2 = edge.X2;
                    if (!rdict.Find(ref x2, out RightNode rnode))
                    {
                        rdict.Add(edge.X2, rnode = new RightNode(edge.X2));
                    }

                    HashSet <RightNode> ledges = newrnodes;
                    if (!edges.FindOrAdd(edge.X1, ref ledges))
                    {
                        newrnodes = new HashSet <RightNode>();
                    }
                    ledges.Add(rnode);
                }

                rightNodes = rdict.Values.ToArray();

                leftNodes = new LeftNode[edges.Count];
                int li = 0;

                foreach (KeyValuePair <TLeftLabel, HashSet <RightNode> > les in edges)
                {
                    leftNodes[li++] = new LeftNode(les.Key, les.Value.ToArray());
                }

                Compute();
            }
コード例 #6
0
ファイル: Node.cs プロジェクト: ZagoskinVA/BinaryTree
 public void AddNode(Tkey key, Tvalue data)
 {
     if (Key.CompareTo(key) == 1)
     {
         if (LeftNode == null)
         {
             LeftNode = new Node <Tkey, Tvalue>(key, data);
         }
         else
         {
             LeftNode.AddNode(key, data);
         }
     }
     else
     {
         if (RightNode == null)
         {
             RightNode = new Node <Tkey, Tvalue>(key, data);
         }
         else
         {
             RightNode.AddNode(key, data);
         }
     }
 }
コード例 #7
0
        /// <summary>
        ///Search for value under current node incusive.
        /// </summary>
        /// <param name="data">Sought value.</param>
        /// <returns>Return list of nodes which satisfy the query</returns>
        internal List <TreeNode <T> > FindUnderNode(T data, IComparer <T> comparer)
        {
            var tempList = new List <TreeNode <T> >();

            if (BinaryTree <T> .CompareValues(data, Value, comparer) == 0)
            {
                tempList.Add(this);
                if (RightNode != null)
                {
                    tempList.AddRange(RightNode.FindUnderNode(data, comparer));
                }
                return(tempList);
            }
            else if (BinaryTree <T> .CompareValues(data, Value, comparer) < 0 && LeftNode != null)
            {
                tempList.AddRange(LeftNode.FindUnderNode(data, comparer));
                return(tempList);
            }
            else if (BinaryTree <T> .CompareValues(data, Value, comparer) > 0 && RightNode != null)
            {
                tempList.AddRange(RightNode.FindUnderNode(data, comparer));
                return(tempList);
            }
            else
            {
                return(tempList);
            }
        }
コード例 #8
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);
         }
     }
 }
コード例 #9
0
        //----------------INSERT NODE----------::START::-----------------------------------------------------------------------------------

        public void InsertNode(int InsertedData)
        {
            if (InsertedData < Data)
            {
                if (LeftNode == null)
                {
                    LeftNode = new BinaryNode(InsertedData);//Crates Node when it finds the correct place
                }
                else
                {
                    //Looping - Rekrusion
                    LeftNode.InsertNode(InsertedData);//Traverse through all nodes till it finds the last node and make the inserted node child
                    //Searching for the coorect place of the Node and when it finds it "Creates the Node - Its the If LeftNode = null"
                }
            }

            else if (InsertedData > Data)//If its bigger than the Data "RIGHT"
            {
                if (RightNode == null)
                {
                    RightNode = new BinaryNode(InsertedData);
                }
                else
                {
                    RightNode.InsertNode(InsertedData);
                }
            }
        }
コード例 #10
0
 public void insertInOrder(int d)
 {
     if (d <= Data)
     {
         if (LeftNode == null)
         {
             LeftNode = new TreeNode(d);
         }
         else
         {
             LeftNode.insertInOrder(d);
         }
     }
     else
     {
         if (RightNode == null)
         {
             RightNode = new TreeNode(d);
         }
         else
         {
             RightNode.insertInOrder(d);
         }
     }
     Size++;
 }
コード例 #11
0
ファイル: HNode.cs プロジェクト: Benji1685/HuffmanEncoding
        public List <bool> TraverseTree(char character, List <bool> data)
        {
            if (!isBranch())
            {
                if (character == this.Character)
                {
                    return(data);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                List <bool> left  = data.ToArray().ToList();
                List <bool> right = data.ToArray().ToList();



                left.Add(true);
                right.Add(false);

                return(RightNode.TraverseTree(character, right) ?? LeftNode.TraverseTree(character, left));
            }
        }
コード例 #12
0
 public void Add(int value)
 {
     //Should go left
     if (value < Value)
     {
         if (LeftNode == null)
         {
             LeftNode = new Node(this, value);
         }
         else
         {
             LeftNode.Add(value);
         }
     }
     else if (value >= Value)
     {
         //Value is greater or equal add right node
         if (RightNode == null)
         {
             RightNode = new Node(this, value);
         }
         else
         {
             RightNode.Add(value);
         }
     }
 }
コード例 #13
0
 public void AddNode(string name, T new_value)
 {
     if (new_value.CompareTo(Value) < 0)
     {
         if (LeftNode == null)
         {
             LeftNode       = new BinaryNode <T>(new_value);
             LeftNode.Value = new_value;
         }
         else
         {
             LeftNode.AddNode(name, new_value);
         }
     }
     else
     {
         if (RightNode == null)
         {
             RightNode       = new BinaryNode <T>(new_value);
             RightNode.Value = new_value;
         }
         else
         {
             RightNode.AddNode(name, new_value);
         }
     }
 }
コード例 #14
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);
         }
     }
 }
コード例 #15
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);
         }
     }
 }
コード例 #16
0
 public void Add(IBinaryTreeNode <TItem> node)
 {
     if (Item.CompareTo(node.Item) > 0)
     {
         if (LeftNode == null)
         {
             LeftNode = node;
         }
         else
         {
             LeftNode.Add(node);
         }
     }
     else if (Item.CompareTo(node.Item) < 0)
     {
         if (RightNode == null)
         {
             RightNode = node;
         }
         else
         {
             RightNode.Add(node);
         }
     }
 }
コード例 #17
0
        public sealed override object Evaluate(NodeEvaluationContext evaluationContext)
        {
            var leftNodeValue = LeftNode.Evaluate(evaluationContext);

            if (leftNodeValue == DependencyProperty.UnsetValue)
            {
                return(DependencyProperty.UnsetValue);
            }

            var leftNodeValueType = GetNodeValueType(leftNodeValue);

            if (leftNodeValueType == NodeValueType.Boolean)
            {
                // give base a chance to yield a result without evaluating the right node
                var result = this.DetermineResultPreRightEvaluation((bool)leftNodeValue);

                if (result.HasValue)
                {
                    return(result.Value);
                }
            }

            var rightNodeValue = RightNode.Evaluate(evaluationContext);

            if (rightNodeValue == DependencyProperty.UnsetValue)
            {
                return(DependencyProperty.UnsetValue);
            }

            var rightNodeValueType = GetNodeValueType(rightNodeValue);

            exceptionHelper.ResolveAndThrowIf(leftNodeValueType != NodeValueType.Boolean || rightNodeValueType != NodeValueType.Boolean, "OperandsNotBoolean", this.OperatorSymbols, leftNodeValueType, rightNodeValueType);

            return(this.DetermineResultPostRightEvaluation((bool)leftNodeValue, (bool)rightNodeValue));
        }
コード例 #18
0
 public void Remove(IBinaryTreeNode <TItem> node, IBinaryTreeNode <TItem> parent)
 {
     if (node.Item.CompareTo(Item) < 0)
     {
         LeftNode?.Remove(node, this);
     }
     else if (node.Item.CompareTo(Item) > 0)
     {
         RightNode?.Remove(node, this);
     }
     else
     {
         if (LeftNode != null && RightNode != null)
         {
             parent.RightNode = MinItem;
         }
         else if (parent.LeftNode == this)
         {
             parent.LeftNode = LeftNode ?? RightNode;
         }
         else if (parent.RightNode == this)
         {
             parent.RightNode = LeftNode ?? RightNode;
         }
     }
 }
コード例 #19
0
            internal void PrintTree(Node MarkNode = null, int Level = 0, String Label = "L")
            {
                string Info = "";

                if (this == MarkNode)
                {
                    Info = " (mark)";
                }

                Console.WriteLine(
                    "{0}- {1}:{2}{3}",
                    new String(' ', Level * 2),
                    Label, this, Info
                    );

                if (LeftNode != null)
                {
                    LeftNode.PrintTree(MarkNode, Level + 1, "L");
                }

                if (RightNode != null)
                {
                    RightNode.PrintTree(MarkNode, Level + 1, "R");
                }
            }
コード例 #20
0
ファイル: Node.cs プロジェクト: Tshmofen/Algorithms-BSU
 public void AddNode(int number)
 {
     if (number < this.Number)
     {
         LeftChilds++;
         if (LeftNode == null)
         {
             LeftNode = new Node(number);
         }
         else
         {
             LeftNode.AddNode(number);
         }
     }
     // skip when number == Number
     else if (number > this.Number)
     {
         RightChilds++;
         if (RightNode == null)
         {
             RightNode = new Node(number);
         }
         else
         {
             RightNode.AddNode(number);
         }
     }
 }
コード例 #21
0
 /// <summary>
 /// Insert value under current node.
 /// </summary>
 /// <param name="data">Stored value.</param>
 internal void InsertUnderNode(T data, IComparer <T> comparer)
 {
     if (BinaryTree <T> .CompareValues(data, Value, comparer) < 0)
     {
         if (LeftNode == null)
         {
             LeftNode = new TreeNode <T>(data, this);
             return;
         }
         else
         {
             LeftNode.InsertUnderNode(data, comparer);
         }
     }
     else
     {
         if (RightNode == null)
         {
             RightNode = new TreeNode <T>(data, this);
             return;
         }
         else
         {
             RightNode.InsertUnderNode(data, comparer);
         }
     }
 }
コード例 #22
0
ファイル: NodeExtensions.cs プロジェクト: ananace/FList-sharp
 public static Block ToBlock(this LeftNode node, Channel _chan = null)
 {
     return(new Paragraph(node.ToInline())
     {
         TextAlignment = TextAlignment.Left
     });
 }
コード例 #23
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);
         }
     }
 }
コード例 #24
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);
                }
            }
        }
コード例 #25
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
コード例 #26
0
        public Node <T> Remove(T data)
        {
            var compared = data.CompareTo(Element);

            if (compared == 0)
            {
                // this element should be removed
                if (LeftNode == null)
                {
                    return(RightNode);
                }
                else if (RightNode == null)
                {
                    return(LeftNode);
                }
                else
                {
                    Element   = RightNode.FindMin();
                    RightNode = RightNode.RemoveMin();
                }
            }
            else if (compared < 0)
            {
                LeftNode = LeftNode?.Remove(data);
            }
            else
            {
                RightNode = RightNode?.Remove(data);
            }

            return(this);
        }
コード例 #27
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);
         }
     }
 }
コード例 #28
0
        public void InsertInOrder(T newNodeData)
        {
            var comparison = newNodeData.CompareTo(Data);

            if (comparison <= 0)
            {
                if (LeftNode == null)
                {
                    SetLeftChild(new TreeNode <T>(newNodeData));
                }
                else
                {
                    LeftNode.InsertInOrder(newNodeData);
                }
            }
            else
            {
                if (RightNode == null)
                {
                    SetRightChild(new TreeNode <T>(newNodeData));
                }
                else
                {
                    RightNode.InsertInOrder(newNodeData);
                }
            }
        }
コード例 #29
0
ファイル: Node.cs プロジェクト: apbertoletti/MyStudies
 public void InsertNode(int value)
 {
     if (value >= Data)
     {
         if (RightNode == null)
         {
             RightNode = new Node(value);
         }
         else
         {
             RightNode.InsertNode(value);
         }
     }
     else
     {
         if (LeftNode == null)
         {
             LeftNode = new Node(value);
         }
         else
         {
             LeftNode.InsertNode(value);
         }
     }
 }
コード例 #30
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);
         }
     }
 }