/// <summary> /// Sorts arrays and returns min time /// </summary> /// <param name="randomArray">Array of integers</param> /// <param name="algorithms">Selected algorithms</param> /// <returns></returns> private static double SortAndGetMinTime(int[] randomArray, int[] algorithms) { int[] copyArray = new int[randomArray.Length]; double min = double.MaxValue; for (int i = 0; i < algorithms.Length; i++) { switch (algorithms[i]) { case 1: Array.Copy(randomArray, copyArray, randomArray.Length); InsertionSort.Sort(copyArray); if (InsertionSort.GetTime() < min) { min = InsertionSort.GetTime(); } break; case 2: Array.Copy(randomArray, copyArray, randomArray.Length); BubbleSort.Sort(copyArray); if (BubbleSort.GetTime() < min) { min = BubbleSort.GetTime(); } break; case 3: Array.Copy(randomArray, copyArray, randomArray.Length); QuickSort.Sort(copyArray); if (QuickSort.GetTime() < min) { min = QuickSort.GetTime(); } break; case 4: Array.Copy(randomArray, copyArray, randomArray.Length); HeapSort.Sort(copyArray); if (HeapSort.GetTime() < min) { min = HeapSort.GetTime(); } break; case 5: Array.Copy(randomArray, copyArray, randomArray.Length); MergeSort.Sort(copyArray); if (MergeSort.GetTime() < min) { min = MergeSort.GetTime(); } break; } } return(min); }
static void Main(string[] args) { var list = new int[] { 8, 56, 42, 4, 75, 1024, 2, 98, 3 }; foreach (var item in list) { Console.Write(item + " "); } Console.WriteLine(); var IS = new QuickSort <int>(); IS.Sort(list); foreach (var item in list) { Console.Write(item + " "); } Console.ReadLine(); }