public Tuple <double, double> RunSearch(int arraySize, int nbArrays)
        {
            Init(arraySize, nbArrays);
            Stopwatch watch;
            double    elapsedMsRedBlack = 0;
            double    elapsedMsAVL      = 0;

            for (int i = 0; i < nbArrays; i++)
            {
                int[] array = (int[])arrays[i].Clone();
                RedBlackTree <int, string> rbTree = new RedBlackTree <int, string>();
                foreach (var v in array)
                {
                    rbTree.Add(v, DateTime.UtcNow.Millisecond.ToString());
                }
                watch = Stopwatch.StartNew();
                rbTree.GetMinKey();
                watch.Stop();
                double ticks        = watch.ElapsedTicks;
                double microseconds = (ticks / Stopwatch.Frequency) * 1000000;
                elapsedMsRedBlack += microseconds;

                AVL AVLtree = new AVL(arrays[i]);
                watch = Stopwatch.StartNew();
                AVLtree.Peek();
                watch.Stop();
                ticks         = watch.ElapsedTicks;
                microseconds  = (ticks / Stopwatch.Frequency) * 1000000;
                elapsedMsAVL += microseconds;
            }
            elapsedMsRedBlack /= nbArrays;
            elapsedMsAVL      /= nbArrays;
            return(new Tuple <double, double>(elapsedMsRedBlack, elapsedMsAVL));
        }
        public Tuple <double, double> RunInsertion(int arraySize, int nbArrays)
        {
            Init(arraySize, nbArrays);
            Stopwatch watch;
            double    elapsedMsRedBlack = 0;
            double    elapsedMsAVL      = 0;

            for (int i = 0; i < nbArrays; i++)
            {
                RedBlackTree <int, string> rbTree = new RedBlackTree <int, string>();
                watch = Stopwatch.StartNew();
                rbTree.Add(0, "0");
                watch.Stop();
                double ticks        = watch.ElapsedTicks;
                double microseconds = (ticks / Stopwatch.Frequency) * 1000000;
                elapsedMsRedBlack += microseconds;

                AVL avltree = new AVL(arrays[i]);
                watch = Stopwatch.StartNew();
                avltree.Add(0);
                watch.Stop();
                ticks         = watch.ElapsedTicks;
                microseconds  = (ticks / Stopwatch.Frequency) * 1000000;
                elapsedMsAVL += microseconds;
            }
            elapsedMsRedBlack /= nbArrays;
            elapsedMsAVL      /= nbArrays;
            return(new Tuple <double, double>(elapsedMsRedBlack, elapsedMsAVL));
        }
示例#3
0
        public static void Driver()
        {
            var rbTree = new RedBlackTree <int, string>();

            for (int i = 1; i <= 40; i++)
            {
                rbTree.Add(i, $"Item : {i}");
            }

            rbTree.DisplayTree();
        }