Exemple #1
0
        public static void TestSorter(ASorter <int> Sorter)
        {
            //Display the sorter type
            Console.WriteLine(Sorter.GetType().Name + " with " + Sorter.Length + " elements");

            //Display the array if it is shorter than 50 elements
            if (Sorter.Length <= 50)
            {
                Console.WriteLine("Before Sort: \n" + Sorter);
            }

            //Calculate the approximate time taken
            long startTime = Environment.TickCount;

            Sorter.Sort();
            long endTime   = Environment.TickCount;
            long finalTime = endTime - startTime;

            if (Sorter.Length <= 50)
            {
                Console.WriteLine("After Sort: \n" + Sorter);
            }
            //Display time elapsed to sort

            Console.WriteLine("Time taken to sort: " + finalTime + " milliseconds");
        }
Exemple #2
0
        static void TestSorter(ASorter <int> sorter)
        {
            // Display sorter type and number of elements
            Console.WriteLine($"{sorter.GetType().Name} object has {sorter.Length} elements");

            if (sorter.Length <= 50)
            {
                Console.WriteLine($"Before sort:\n{sorter}\n");
            }

            long startTime = Environment.TickCount;

            sorter.Sort();
            long endTime = Environment.TickCount;

            if (sorter.Length <= 50)
            {
                Console.WriteLine($"After sort:\n{sorter}\n");
            }

            Console.WriteLine($"Time elapsed: {endTime - startTime} ms");
        }