예제 #1
0
        static void Main(string[] args)
        {
            IList <int> list = new List <int> {
                23, 42, 4, 16, 8, 15, 3, 9, 55, 0, 34, 12, 2, 46, 25
            };

            list = Quicksort.Sort(list, 0, list.Count - 1);

            Console.ReadKey();
        }
예제 #2
0
파일: Program.cs 프로젝트: TheMoo75/Sort
        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();
        }
예제 #3
0
파일: Program.cs 프로젝트: TheMoo75/Sort
        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();
        }