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(); }
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(); }
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(); }