Beispiel #1
0
        public static void averrageTest()
        {
            Random              random        = new Random();
            DateTime            firstDayMonth = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)).Date;
            DateTime            lastDayMonth  = (firstDayMonth.AddMonths(1).AddDays(-1)).Date;
            DynamicArray <Baby> array         = new DynamicArray <Baby>();

            for (int i = 0; i < 10; i++)
            {
                array.add(new Baby(Convert.ToInt16(random.Next(2600, 4001)), Convert.ToByte(random.Next(46, 55)), (new DateTime(DateTime.Now.Year, DateTime.Now.Month, random.Next(firstDayMonth.Day, lastDayMonth.Day + 1))).Date));
            }

            AVLTree <Baby> treeSize   = new AVLTree <Baby>(CompareType.Size);
            AVLTree <Baby> treeDate   = new AVLTree <Baby>(CompareType.Date);
            AVLTree <Baby> treeWeight = new AVLTree <Baby>(CompareType.Weight);

            for (int i = 0; i < array.count; i++)
            {
                treeSize.Root = treeSize.insert(treeSize.Root, array[i]);
            }
            for (int i = 0; i < array.count; i++)
            {
                treeDate.Root = treeDate.insert(treeDate.Root, array[i]);
            }
            for (int i = 0; i < array.count; i++)
            {
                treeWeight.Root = treeWeight.insert(treeWeight.Root, array[i]);
            }

            Console.Write("============Size============ \r\n");
            Console.Write("The visual representation of the tree is : \r\n");
            treeSize.PrintTree(treeSize.Root);

            Console.Write("The averrage (size) is : \r\n");
            Console.Write(Convert.ToDecimal(treeSize.Averrage(treeSize.Root)).ToString("#.##"));

            Console.Write("\r\n ============Date============ \r\n");
            Console.Write("The visual representation of the tree is : \r\n");
            treeSize.PrintTree(treeDate.Root);

            Console.Write("The averrage (size) is : \r\n");
            Console.Write(Convert.ToDateTime(treeDate.Averrage(treeDate.Root)).ToString("dd.MM.yyyy"));

            Console.Write("\r\n ============Weight============ \r\n");
            Console.Write("The visual representation of the tree is : \r\n");
            treeSize.PrintTree(treeWeight.Root);

            Console.Write("The averrage (size) is : \r\n");
            Console.Write(Convert.ToDecimal(treeWeight.Averrage(treeWeight.Root)).ToString("#.##"));
        }
Beispiel #2
0
        public static void treeMergeTest()
        {
            Random              random        = new Random();
            DateTime            firstDayMonth = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)).Date;
            DateTime            lastDayMonth  = (firstDayMonth.AddMonths(1).AddDays(-1)).Date;
            DynamicArray <Baby> array         = new DynamicArray <Baby>();
            DynamicArray <Baby> array2        = new DynamicArray <Baby>();
            DynamicArray <Baby> array3        = new DynamicArray <Baby>();

            for (int i = 0; i < 5; i++)
            {
                array.add(new Baby(Convert.ToInt16(random.Next(2600, 4001)), Convert.ToByte(random.Next(46, 55)), (new DateTime(DateTime.Now.Year, DateTime.Now.Month, random.Next(firstDayMonth.Day, lastDayMonth.Day + 1))).Date));
            }
            for (int i = 0; i < 5; i++)
            {
                array2.add(new Baby(Convert.ToInt16(random.Next(2600, 4001)), Convert.ToByte(random.Next(46, 55)), (new DateTime(DateTime.Now.Year, DateTime.Now.Month, random.Next(firstDayMonth.Day, lastDayMonth.Day + 1))).Date));
            }
            for (int i = 0; i < 5; i++)
            {
                array3.add(new Baby(Convert.ToInt16(random.Next(2600, 4001)), Convert.ToByte(random.Next(46, 55)), (new DateTime(DateTime.Now.Year, DateTime.Now.Month, random.Next(firstDayMonth.Day, lastDayMonth.Day + 1))).Date));
            }

            AVLTree <Baby> treeSize  = new AVLTree <Baby>(CompareType.Size);
            AVLTree <Baby> treeSize2 = new AVLTree <Baby>(CompareType.Size);
            AVLTree <Baby> treeSize3 = new AVLTree <Baby>(CompareType.Size);

            for (int i = 0; i < array.count; i++)
            {
                treeSize.Root = treeSize.insert(treeSize.Root, array[i]);
            }
            for (int i = 0; i < array2.count; i++)
            {
                treeSize2.Root = treeSize2.insert(treeSize2.Root, array2[i]);
            }
            for (int i = 0; i < array3.count; i++)
            {
                treeSize3.Root = treeSize3.insert(treeSize3.Root, array3[i]);
            }


            Console.Write("\r\n ============Size============ \r\n");
            Console.Write("The visual representation of the tree is : \r\n");
            treeSize.PrintTree(treeSize.Root);

            Console.Write("The averrage (size) is : \r\n");
            Console.Write(Convert.ToDecimal(treeSize.Averrage(treeSize.Root)).ToString("#.##"));

            Console.Write("\r\n ============Size2============ \r\n");
            Console.Write("The visual representation of the tree is : \r\n");
            treeSize.PrintTree(treeSize2.Root);

            Console.Write("The averrage (size) is : \r\n");
            Console.Write(Convert.ToDecimal(treeSize2.Averrage(treeSize2.Root)).ToString("#.##"));

            Console.Write("\r\n ============Size3============ \r\n");
            Console.Write("The visual representation of the tree is : \r\n");
            treeSize.PrintTree(treeSize3.Root);

            Console.Write("The averrage (size) is : \r\n");
            Console.Write(Convert.ToDecimal(treeSize3.Averrage(treeSize3.Root)).ToString("#.##"));


            DynamicArray <AVLTree <Baby> > treeArray = new DynamicArray <AVLTree <Baby> >();

            treeArray.add(treeSize);
            treeArray.add(treeSize2);
            treeArray.add(treeSize3);

            AVLTree <Baby> tree = mergeTree(treeArray);

            Console.Write("\r\n ============Merged Tree============ \r\n");
            Console.Write("The visual representation of the tree is : \r\n");
            tree.PrintTree(tree.Root);

            Console.Write("The averrage (size) is : \r\n");
            Console.Write(Convert.ToDecimal(tree.Averrage(tree.Root)).ToString("#.##"));
        }