Exemple #1
0
        static void Sort(int amountNumbers,string sortMethod)
        {
            Quicksort quicksort = new Quicksort();
            Bubblesort bubblesort = new Bubblesort();
            int[] sorted = {};

            int[] unsorted = RandomArray(amountNumbers);

            Console.WriteLine("Unsorted");
            Console.WriteLine();

            for (int count = 0; count < unsorted.Count(); count++)
            {
                Console.Write(unsorted[count] + " ");
            }
            Console.WriteLine();

            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            
            switch (sortMethod)
            {
                case "quicksort":
                    sorted = quicksort.Sort(unsorted);
                    break;
                case "bubblesort":
                    sorted = bubblesort.Sort(unsorted);
                    break;
            }
            
            stopWatch.Stop();

            Console.WriteLine();
            Console.WriteLine("Sorted using the " + sortMethod + " algorithm");
            Console.WriteLine();

            for (int count = 0; count < sorted.Count(); count++)
            {
                Console.Write(unsorted[count] + " ");
            }
            Console.WriteLine();

            TimeSpan ts = stopWatch.Elapsed;

            Console.WriteLine("RunTime " + stopWatch.Elapsed);
            Console.WriteLine();
            Console.WriteLine("Press return to continue");
            Console.WriteLine();
            Console.ReadLine();
        }