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 + "; ");
            }
        }
Beispiel #2
0
        /// <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;
            }
        }
Beispiel #3
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 + "; ");
            }
        }