예제 #1
0
        public void ShellDown(int[] array, typeofarray typeofArray)
        {
            AlgorythmsWork aw             = new AlgorythmsWork();
            DateTime       dtStartWorking = DateTime.Now;

            aw.comparecount   = 0;
            aw.reshufflecount = 0;
            int[] H  = { 20, 10, 4, 1 };
            int   HN = H.Length;

            foreach (int step in H)
            {
                for (int i = 0 + step; i <= array.Length - 1; i++)
                {
                    int j   = i;
                    int tmp = array[i];
                    while (j >= 0 + step && tmp > array[j - step] && aw.comparecount++ != -1)
                    {
                        aw.reshufflecount++;
                        array[j] = array[j - step];
                        j       -= step;
                    }
                    array[j] = tmp;
                }
            }
            aw.time           = GetWorkLastAlgorythm(dtStartWorking, DateTime.Now);
            aw.namealgorythms = "Shell down";
            aw.typeArray      = typeofArray;
            aw.array          = array;
            algorythmData.Add(aw);
            Console.WriteLine("{0} отработал. Тип массива: {1}", aw.namealgorythms, aw.typeArray);
        }
예제 #2
0
        public void ChoiceDown(int[] array, typeofarray typeofArray)
        {
            AlgorythmsWork aw             = new AlgorythmsWork();
            DateTime       dtStartWorking = DateTime.Now;

            aw.comparecount   = 0;
            aw.reshufflecount = 0;
            for (int i = 0; i <= array.Length - 1; i++)
            {
                int max = i;
                for (int j = i + 1; j <= array.Length - 1; j++)
                {
                    aw.comparecount++;
                    if (array[j] > array[max])
                    {
                        max = j;
                    }
                }
                int tmp = array[i];
                array[i]   = array[max];
                array[max] = tmp;
                aw.reshufflecount++;
            }
            aw.time           = GetWorkLastAlgorythm(dtStartWorking, DateTime.Now);
            aw.namealgorythms = "Choice down";
            aw.typeArray      = typeofArray;
            aw.array          = array;
            algorythmData.Add(aw);
            Console.WriteLine("{0} отработал. Тип массива: {1}", aw.namealgorythms, aw.typeArray);
        }
예제 #3
0
        public void InsertsDown(int[] array, typeofarray typeofArray)
        {
            AlgorythmsWork aw             = new AlgorythmsWork();
            DateTime       dtStartWorking = DateTime.Now;

            aw.comparecount   = 0;
            aw.reshufflecount = 0;
            for (int i = 1; i < array.Length; i++)
            {
                int j   = i;
                int key = array[i];
                while (aw.comparecount++ != -1 & j > 0 && key > array[j - 1])
                {
                    aw.reshufflecount++;
                    array[j] = array[j - 1];
                    j--;
                }
                array[j] = key;
            }
            aw.time           = GetWorkLastAlgorythm(dtStartWorking, DateTime.Now);
            aw.namealgorythms = "Insert down";
            aw.typeArray      = typeofArray;
            aw.array          = array;
            algorythmData.Add(aw);
            Console.WriteLine("{0} отработал. Тип массива: {1}", aw.namealgorythms, aw.typeArray);
        }
예제 #4
0
        public void BubbleUp(int[] array, typeofarray typeofArray)
        {
            AlgorythmsWork aw             = new AlgorythmsWork();
            DateTime       dtStartWorking = DateTime.Now;

            aw.comparecount   = 0;
            aw.reshufflecount = 0;
            for (int i = 0; i <= array.Length - 2; i++)
            {
                for (int j = i + 1; j <= array.Length - 1; j++)
                {
                    aw.comparecount++;
                    if (array[i] > array[j])
                    {
                        aw.reshufflecount++;
                        int tmp = array[i];
                        array[i] = array[j];
                        array[j] = tmp;
                    }
                }
            }
            aw.time           = GetWorkLastAlgorythm(dtStartWorking, DateTime.Now);
            aw.namealgorythms = "Bubble up";
            aw.typeArray      = typeofArray;
            aw.array          = array;
            algorythmData.Add(aw);
            Console.WriteLine("{0} отработал. Тип массива: {1}", aw.namealgorythms, aw.typeArray);
        }
예제 #5
0
        public void ShakerDown(int[] array, typeofarray typeofArray)
        {
            int            l              = 0;
            int            r              = array.Length - 1;
            AlgorythmsWork aw             = new AlgorythmsWork();
            DateTime       dtStartWorking = DateTime.Now;

            aw.comparecount   = 0;
            aw.reshufflecount = 0;
            do
            {
                //Сдвигаем к концу массива "тяжелые элементы"
                for (int i = l; i < r; i++)
                {
                    aw.comparecount++;
                    if (array[i] < array[i + 1])
                    {
                        aw.reshufflecount++;
                        int tmp = array[i];
                        array[i]     = array[i + 1];
                        array[i + 1] = tmp;
                    }
                }
                r--;
                //Сдвигаем к началу массива "легкие элементы"
                for (int i = r; i > l; i--)
                {
                    aw.comparecount++;
                    if (array[i] > array[i - 1])
                    {
                        aw.reshufflecount++;
                        int tmp = array[i];
                        array[i]     = array[i - 1];
                        array[i - 1] = tmp;
                    }
                }
                l++;
            }while (l <= r);
            aw.time           = GetWorkLastAlgorythm(dtStartWorking, DateTime.Now);
            aw.namealgorythms = "Shaker down";
            aw.typeArray      = typeofArray;
            aw.array          = array;
            algorythmData.Add(aw);
            Console.WriteLine("{0} отработал. Тип массива: {1}", aw.namealgorythms, aw.typeArray);
        }
예제 #6
0
        static List <AlgorythmsWork> SortAlgorythms(List <AlgorythmsWork> algorythmData)
        {
            List <AlgorythmsWork> sortedAlgUnFull = new List <AlgorythmsWork>();
            List <AlgorythmsWork> sortedAlgFull   = new List <AlgorythmsWork>();

            for (int i = 0; i < algorythmData.Count - 1; i++)// получение только рандом массивов
            {
                if (algorythmData[i].typeArray == typeofarray.Random)
                {
                    sortedAlgUnFull.Add(algorythmData[i]);
                }
            }
            for (int i = 1; i < sortedAlgUnFull.Count; i++)
            {
                int            j   = i;
                AlgorythmsWork tmp = sortedAlgUnFull[i];
                while (j > 0 && tmp.time.CompareTo(sortedAlgUnFull[j - 1].time) == 1)
                {
                    sortedAlgUnFull[j] = sortedAlgUnFull[j - 1];
                    j--;
                }
                sortedAlgUnFull[j] = tmp;
            }
            sortedAlgFull.AddRange(sortedAlgUnFull);
            sortedAlgUnFull.Clear();
            for (int i = 0; i < algorythmData.Count - 1; i++)// получение только рандом массивов
            {
                if (algorythmData[i].typeArray == typeofarray.SortedUp)
                {
                    sortedAlgUnFull.Add(algorythmData[i]);
                }
            }
            for (int i = 1; i < sortedAlgUnFull.Count; i++)
            {
                int            j   = i;
                AlgorythmsWork tmp = sortedAlgUnFull[i];
                while (j > 0 && tmp.time.CompareTo(sortedAlgUnFull[j - 1].time) == 1)
                {
                    sortedAlgUnFull[j] = sortedAlgUnFull[j - 1];
                    j--;
                }
                sortedAlgUnFull[j] = tmp;
            }
            sortedAlgFull.AddRange(sortedAlgUnFull);
            sortedAlgUnFull.Clear();
            for (int i = 0; i < algorythmData.Count - 1; i++)// получение только рандом массивов
            {
                if (algorythmData[i].typeArray == typeofarray.SortedDown)
                {
                    sortedAlgUnFull.Add(algorythmData[i]);
                }
            }
            for (int i = 1; i < sortedAlgUnFull.Count; i++)
            {
                int            j   = i;
                AlgorythmsWork tmp = sortedAlgUnFull[i];
                while (j > 0 && tmp.time.CompareTo(sortedAlgUnFull[j - 1].time) == 1)
                {
                    sortedAlgUnFull[j] = sortedAlgUnFull[j - 1];
                    j--;
                }
                sortedAlgUnFull[j] = tmp;
            }
            sortedAlgFull.AddRange(sortedAlgUnFull);
            return(sortedAlgFull);
        }