public static void ConsoleInterface() { //Initializing array Random rand = new Random(); string[] a = new string[100]; Console.WriteLine("Array before sorting:"); for (int i = 0; i < a.Length; i++) { a[i] = ""; int temp = rand.Next(0, 10); for (int k = 0; k < temp; k++) { a[i] += i; } //Printing element Console.Write(a[i] + "; "); } //Sorting array by comparing strings by their lengths CustomSort <string> .MergeSort(a, Comparison <string> .CompareStringByLength); //Printing the sorted array Console.WriteLine(Environment.NewLine + "Array after sorting:"); foreach (var item in a) { Console.Write(item + "; "); } }
public static void SortThread <T>(T[] array, Func <T, T, bool> comparator) { int threadId = ++_threadID; Thread newThread = new Thread(() => CustomSort.Sort(ref array, comparator)); newThread.Start(); newThread.Join(); Finish?.Invoke($"Sorting is finished in Thread with ID {threadId}."); }
/// <summary> /// Sorts array with a specified comparison function. /// </summary> public static new void MergeSort(T[] array, ComparisonFunction <T> compare) { //Subscription to event onSortingDone += SortingDoneSubscriber; //Invoking sort method from the base class CustomSort <T> .MergeSort(array, compare); //Invoking all subscribed methods onSortingDone?.Invoke(new object(), new SortingEventArgs <T>(array)); //Unsubscription to event if (onSortingDone != null) { onSortingDone -= SortingDoneSubscriber; } }
static void Main() { double selection; do { Console.WriteLine("4,1 CUSTOM SORT."); Console.WriteLine("4,2 CUSTOM SORT DEMO."); Console.WriteLine("4,3 SORTING UNIT."); Console.WriteLine("4,4 NUMBER ARRAY SUM."); Console.WriteLine("4,5 TO INT OR NOT TO INT?"); Console.WriteLine("4,6 I SEEK YOU."); Console.WriteLine("0 Exit."); Console.WriteLine(); if (double.TryParse(Console.ReadLine(), out selection)) { switch (selection) { case 4.1: CustomSort.ShowFirstTask(); break; case 4.2: CustomSort.ShowSecondTask(); break; case 4.3: SortingUnit.Show(); break; case 4.4: NumberArraySum.ShowFourthTask(); break; case 4.5: NumberArraySum.ShowFifthTask(); break; case 4.6: ISeekYou.Show(); break; case 0: break; } } } while (selection != 0); }
public static void ConsoleInterface() { //Initializing new array Random rand = new Random(); float[] a = new float[100]; Console.WriteLine("Array before sorting:"); for (int i = 0; i < a.Length; i++) { a[i] = rand.Next(0, 100) / 100.0f; //Printing element Console.Write(a[i] + "; "); } //Sorting array CustomSort <float> .MergeSort(a, Comparison <float> .CompareFloat); //Printing the sorted array Console.WriteLine(Environment.NewLine + "Array after sorting:"); foreach (var item in a) { Console.Write(item + "; "); } }