Example #1
0
        public void ToString_RootLeft()
        {
            AVLNode <int> node = new AVLNode <int>(50)
            {
                Left = new AVLNode <int>(25),
            };

            Assert.AreEqual <string>("50; Left=25; Right=null", node.ToString());
        }
Example #2
0
        public void ToString_RootRight()
        {
            AVLNode <int> node = new AVLNode <int>(50)
            {
                Right = new AVLNode <int>(75),
            };

            Assert.AreEqual <string>("50; Left=null; Right=75", node.ToString());
        }
Example #3
0
        public void ToString_RootRight()
        {
            AVLNode<int> node = new AVLNode<int>(50)
            {
                Right = new AVLNode<int>(75),
            };

            Assert.AreEqual<string>("50; Left=null; Right=75", node.ToString());
        }
Example #4
0
        public void ToString_RootLeft()
        {
            AVLNode<int> node = new AVLNode<int>(50)
            {
                Left = new AVLNode<int>(25),
            };

            Assert.AreEqual<string>("50; Left=25; Right=null", node.ToString());
        }
Example #5
0
 internal string ToString(int count)
 {
     return((right != null ? right.ToString(count + 4) : new string(' ', count + 4) + "+ null") + "\n" + new string(' ', count) + (isLeft ? "L" : "R") + " \"" + key.ToString() + "\" : \"" + value.ToString() + "\" (" + balance + " | L" + _depthL + "R" + _depthR + ") \n" + (left != null ? left.ToString(count + 4) : new string(' ', count + 4) + "+ null"));
 }
Example #6
0
            private static int CheckBalance(AVLNode node)
            {
                int r = 0, l = 0;

                if (node.right != null)
                {
                    r = CheckBalance(node.right) + 1;
                }

                if (node.left != null)
                {
                    l = CheckBalance(node.left) + 1;
                }

                System.Diagnostics.Debug.Assert(node._depthL == l, "Invalid Depth L (is " + node._depthL + " should be " + l + ")", node.ToString());
                System.Diagnostics.Debug.Assert(node._depthR == r, "Invalid Depth R (is " + node._depthR + " should be " + r + ")", node.ToString());

                return(Math.Max(r, l));
            }
Example #7
0
            private static void CheckSide(AVLNode node)
            {
                if (node.right != null)
                {
                    System.Diagnostics.Debug.Assert(!node.right.isLeft, "The Node to the Right is not marked as !isLeft", node.ToString());
                    CheckSide(node.right);
                }

                if (node.left != null)
                {
                    System.Diagnostics.Debug.Assert(node.left.isLeft, "The Node to the Left is not marked as isLeft", node.ToString());
                    CheckSide(node.left);
                }
            }