public static long QuickSortTime(float[] array, TimeType type) => QuickSortAlgorithm.Time(array, type); //returns time /// <summary> /// Returns prepared message of duration in ticks. /// </summary> /// <param name="array">Float array to sort.</param> /// <param name="type">Type of returned duration.</param> public static string QuickSortTimePrint(float[] array, TimeType type) { if (type == TimeType.Both) { return(string.Format("Quick Sorting Duration: {0} Miliseconds / {1} Ticks.", QuickSortAlgorithm.Time(array, TimeType.Miliseconds), QuickSortAlgorithm.Time(array, TimeType.Ticks))); //returns preprepared messageof time } return(string.Format("Quick Sorting Duration: {0} {1}", QuickSortAlgorithm.Time(array, type), type == TimeType.Ticks ? "Ticks." : "Miliseconds.")); //returns preprepared message of time }
static void Main(string[] args) { //int[] numArray = { 89, 76, 45, 92, 67, 12, 99 }; int[] numArray = { 100, 89, 69, 49, 39, 15, 1 }; //int[] numArray = { 89, 76, 45, 92, 67, 12, 99 }; ISortAlgorithm bubbleSorter = new BubbleSortAlgorithm(); Console.WriteLine("Before Bubble Sort"); PrintArray(numArray); bubbleSorter.SortNumbers(ref numArray); Console.WriteLine("After Bubble Sort"); PrintArray(numArray); int[] numArray1 = { 1, 16, 35, 25, 65, 85, 99 }; ISortAlgorithm insertionSorter = new InsertionSortAlgorithm(); Console.WriteLine("Before Insertion Sort"); PrintArray(numArray1); insertionSorter.SortNumbers(ref numArray1); Console.WriteLine("After Insertion Sort"); PrintArray(numArray1); int[] numArray2 = { 99, 1, 36, 0, 32, 9, 89 }; ISortAlgorithm selectionSorter = new SelectionSortAlgorithm(); Console.WriteLine("Before Selection Sort"); PrintArray(numArray2); selectionSorter.SortNumbers(ref numArray2); Console.WriteLine("After Selection Sort"); PrintArray(numArray2); int[] numArray3 = { 89, 76, 45, 92, 67, 12, 99 }; ISortAlgorithm mergeSorter = new MergeSortAlgorithm(); Console.WriteLine("Before Merge Sort"); PrintArray(numArray3); mergeSorter.SortNumbers(ref numArray3); Console.WriteLine("After Merge Sort"); PrintArray(numArray3); int[] numArray4 = { 89, 76, 45, 92, 67, 12, 99 }; ISortAlgorithm quickSorter = new QuickSortAlgorithm(); Console.WriteLine("Before Quick Sort"); PrintArray(numArray4); quickSorter.SortNumbers(ref numArray4); Console.WriteLine("After Quick Sort"); PrintArray(numArray4); int[] numArrayCountSort = { 99, 1, 36, 0, 32, 9, 89 }; ISortAlgorithm countSorter = new CountingSortAlgorithm(); Console.WriteLine("Before Count Sort"); PrintArray(numArrayCountSort); countSorter.SortNumbers(ref numArrayCountSort); Console.WriteLine("After Count Sort"); PrintArray(numArrayCountSort); int[] numArrayBucketSort = { 99, 1, 36, 5, 32, 9, 89 }; ISortAlgorithm bucketSorter = new BucketSortAlgorithm(); Console.WriteLine("Before Bucket Sort"); PrintArray(numArrayBucketSort); bucketSorter.SortNumbers(ref numArrayBucketSort); Console.WriteLine("After Bucket Sort"); PrintArray(numArrayBucketSort); CountInversionInMergeSort(); Console.ReadLine(); }
/// <summary> /// Returns duration of algorithm calculations in ticks. /// </summary> /// <param name="array">Float array to sort.</param> /// <param name="type">Type of returned duration.</param> public static long QuickSortTime(float[] array, TimeType type) => QuickSortAlgorithm.Time(array, type); //returns time
/// <summary> /// Sorting an double array with using quick sort algorithm. /// </summary> /// <param name="array">Double array to sort.</param> public static void QuickSort(double[] array) => QuickSortAlgorithm.QuickSort(array, 0, array.Length - 1);