Ejemplo n.º 1
0
        static void TestHeightDiff()
        {
            AVLT <int> avlt = new AVLT <int>();

            avlt.Add(10);
            avlt.Add(15);
            avlt.Add(20);
        }
Ejemplo n.º 2
0
        static void TestRotations()
        {
            Console.WriteLine("Single Left");
            AVLT <int> avltLL = new AVLT <int>();

            avltLL.Add(10);
            avltLL.Add(15);
            avltLL.Add(13);
            avltLL.Add(20);
            //Console.WriteLine("Pre-Rotate:\t ");
            avltLL.Iterate(DoSomethingToAnInt, TraversalOrder.PRE_ORDER);
            //avltLL.TestLL();
            //Console.WriteLine("\nPost-Rotate: \t ");
            //avltLL.Iterate(DoSomethingToAnInt, TraversalOrder.PRE_ORDER);


            Console.WriteLine("\n\nSingle Right");
            AVLT <int> avltRR = new AVLT <int>();

            avltRR.Add(10);
            avltRR.Add(5);
            avltRR.Add(2);
            //Console.WriteLine("Pre-Rotate:\t ");
            avltRR.Iterate(DoSomethingToAnInt, TraversalOrder.PRE_ORDER);
            //avltRR.TestRR();
            //Console.WriteLine("\nPost-Rotate:\t ");
            //avltRR.Iterate(DoSomethingToAnInt, TraversalOrder.PRE_ORDER);



            Console.WriteLine("\n\nDouble Left");
            AVLT <int> avltLR = new AVLT <int>();

            avltLR.Add(5);
            avltLR.Add(10);
            avltLR.Add(8);
            //Console.WriteLine("Pre-Rotate:\t ");
            avltLR.Iterate(DoSomethingToAnInt, TraversalOrder.PRE_ORDER);
            //avltLR.TestLR();
            //Console.WriteLine("\nPost-Rotate:\t ");
            //avltLR.Iterate(DoSomethingToAnInt, TraversalOrder.PRE_ORDER);


            Console.WriteLine("\nDouble Right");
            AVLT <int> avltRL = new AVLT <int>();

            avltRL.Add(10);
            avltRL.Add(5);
            avltRL.Add(8);
            avltRL.Iterate(DoSomethingToAnInt, TraversalOrder.PRE_ORDER);
            //Console.WriteLine("\nPre-Rotate:");
            //avltRL.TestRL();
            //avltRL.Iterate(DoSomethingToAnInt, TraversalOrder.PRE_ORDER);
            //Console.WriteLine("Post-Rotate:");
        }
Ejemplo n.º 3
0
        static void TestRandomAVLT()
        {
            long start;
            long end;

            AVLT <int> balanceTree = new AVLT <int>();

            //BST<int> balanceTree = new BST<int>();

            start = Environment.TickCount;
            Random randomNumber = new Random((int)start);
            int    iMax         = 10000;
            int    iLargest     = iMax * 10;

            List <int> remove = new List <int>();

            int add;

            for (int i = 0; i < iMax; i++)
            {
                add = randomNumber.Next(1, iLargest);

                balanceTree.Add(add);

                if (i % 10 == 0)
                {
                    remove.Add(add);
                }
            }

            if (balanceTree.Count <= 50)
            {
                Console.WriteLine(balanceTree.ToString());
            }

            end = Environment.TickCount;

            Console.WriteLine("Time to Add: \t" + (end - start).ToString() + " ms");
            Console.WriteLine("Theoretical Minimum Height: \t " + Math.Truncate(Math.Log(iMax, 2)));
            Console.WriteLine("Actual Height: \t " + balanceTree.Height());

            foreach (int item in remove)
            {
                balanceTree.Remove(item);
            }

            if (balanceTree.Count <= 50)
            {
                Console.WriteLine(balanceTree.ToString());
            }
            //balanceTree.Iterate(DoSomethingToAnInt, TraversalOrder.IN_ORDER);
            Console.WriteLine("Count: \t" + balanceTree.Count);
            Console.WriteLine("Actual Height: \t " + balanceTree.Height());
        }