Пример #1
0
        // Not Unity //
#if !UNITY_5_3_OR_NEWER
        public static T[] SelectionSort_Debug <T>(this T[] array) where T : IComparable
        {
            int ifCount = 0, matchIfCount = 0, swapCount = 0;

            T[] result = (T[])array.Clone();
            for (int i = 0; i < result.Length; i++)
            {
                int maxIndex = 0;
                for (int j = 0; j < result.Length - i; j++)
                {
                    MyArray.Println(result, Color.LightGreen, j, maxIndex);
                    ifCount++;
                    if (result[j].CompareTo(result[maxIndex]) > 0)
                    {
                        matchIfCount++;
                        MyArray.Println(result, Color.Yellow, j, maxIndex);
                        maxIndex = j;
                    }
                }
                Swap(ref result[maxIndex], ref result[result.Length - 1 - i]);
                MyArray.Println(result, Color.Red, maxIndex, result.Length - 1 - i);
                swapCount++;
            }
            Console.WriteLine("Check condition (Green) times: " + ifCount);
            Console.WriteLine("Match condition (Yellow) times: " + matchIfCount);
            Console.WriteLine("Swap (Red) times: " + swapCount);
            return(result);
        }
Пример #2
0
        // Not Unity //
#if !UNITY_5_3_OR_NEWER
        public static T[] BubbleSort_Debug <T>(this T[] array) where T : IComparable
        {
            int ifCount = 0, matchIfCount = 0, swapCount = 0;

            T[] result = (T[])array.Clone();
            for (int i = 0; i < result.Length; i++)
            {
                for (int j = 1; j < result.Length - i; j++)
                {
                    MyArray.Println(result, Color.LightGreen, j - 1, j);
                    ifCount++;
                    if (result[j - 1].CompareTo(result[j]) > 0)
                    {
                        matchIfCount++;
                        MyArray.Println(result, Color.Yellow, j - 1, j);
                        Swap(ref result[j - 1], ref result[j]);
                        MyArray.Println(result, Color.Red, j - 1, j);
                        swapCount++;
                    }
                }
            }
            Console.WriteLine("Check condition (Green) times: " + ifCount);
            Console.WriteLine("Match condition (Yellow) times: " + matchIfCount);
            Console.WriteLine("Swap (Red) times: " + swapCount);
            return(result);
        }