public void TestCompareTo()
        {
            BinaryNode <int> testBinaryNode       = new BinaryNode <int>(element: 20);
            BinaryNode <int> testLowerBinaryNode  = new BinaryNode <int>(element: 10);
            BinaryNode <int> testHigherBinaryNode = new BinaryNode <int>(element: 30);
            BinaryNode <int> testEqualBinaryNode  = new BinaryNode <int>(element: 20);
            int comparisonEqual  = testBinaryNode.CompareTo(element: testEqualBinaryNode.Element);
            int comparisonLower  = testBinaryNode.CompareTo(element: testLowerBinaryNode.Element);
            int comparisonHigher = testBinaryNode.CompareTo(element: testHigherBinaryNode.Element);

            Assert.AreEqual(0, comparisonEqual);
            Assert.AreEqual(1, comparisonLower);
            Assert.AreEqual(-1, comparisonHigher);
        }
Ejemplo n.º 2
0
        private void AddRecursively(BinaryNode currentNode, BinaryNode newNode)
        {
            if (newNode.CompareTo(currentNode) >= 0)
            {
                if (currentNode.RightChild == null)
                {
                    currentNode.RightChild = newNode;
                    return;
                }

                AddRecursively(currentNode.RightChild, newNode);
            }
            else
            {
                if (currentNode.LeftChild == null)
                {
                    currentNode.LeftChild = newNode;
                    return;
                }

                AddRecursively(currentNode.LeftChild, newNode);
            }
        }
Ejemplo n.º 3
0
 private bool IsLeftOfParent(BinaryNode nodeToRemove, BinaryNode parentNode)
 {
     return(nodeToRemove.CompareTo(parentNode) < 0);
 }