Example #1
0
        static void Print_Trees_fixed()
        {
            var tree = new Tree();

            int[] keys  = new int[] { 1, 4, 5, 7, 12, 13, 15, 14, 20, 16, 26, 32, 34, 32, 33, 37, 38, 38, 40, 39, 39, 44, 43, 48, 46 };
            int[] keys2 = new int[] { 37, 1, 40, 32, 39, 44, 13, 34, 38, 39, 43, 48, 46, 38, 7, 15, 32, 5, 12, 14, 20, 33, 4, 16, 26 };

            var count = keys.Length;

            for (int i = 0; i < count; i++)
            {
                tree.Add(keys2[i]);
            }

            tree.Print();
            foreach (var key in tree.SortedKeys())
            {
                Console.Write(key + ",");
            }
            Console.WriteLine("({0})", count);
        }
Example #2
0
        static void MeasureTime(int count, int range)
        {
            var        tree  = new Tree();
            var        rand  = new Random();
            List <int> list  = new List <int>();
            var        watch = new System.Diagnostics.Stopwatch();

            watch.Start();
            for (int i = 0; i < count; i++)
            {
                int key = rand.Next(0, range);
                tree.Add(key);
                list.Add(key);
            }
            watch.Stop();
            Console.Write(count + "\t" + range + "\t  |\t");
            Console.Write(watch.Elapsed.TotalMilliseconds);
            //tree.Print(PrintStyle.Better);

            watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            var sortedList = tree.SortedKeys();

            watch.Stop();
            Console.Write("\t\t");
            Console.Write(watch.Elapsed.TotalMilliseconds);

            watch.Restart();
            list.Sort();
            watch.Stop();
            Console.Write("\t\t");
            Console.WriteLine(watch.Elapsed.TotalMilliseconds);

            //foreach (var item in sortedList)
            //{
            //    Console.Write(item);
            //    Console.Write("; ");
            //}
        }