示例#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
        static void GenerateArray(int[] intArray, typeofarray typeofArray)
        {
            Random rnd = new Random();

            switch (typeofArray)
            {
            case typeofarray.Random:
                for (int i = 0; i <= intArray.Length - 1; i++)
                {
                    intArray[i] = rnd.Next(20);
                }
                break;

            case typeofarray.SortedDown:
                for (int i = intArray.Length - 1; i >= 0; i--)
                {
                    intArray[i] = i;
                }
                break;

            case typeofarray.SortedUp:
                for (int i = 0; i <= intArray.Length - 1; i++)
                {
                    intArray[i] = i;
                }
                break;
            }
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
0
 public void GetTest(int[] intArray, typeofarray typeofArray)
 {
     BubbleUp(CopyArray(intArray), typeofArray);
     BubbleDown(CopyArray(intArray), typeofArray);
     InsertsUp(CopyArray(intArray), typeofArray);
     InsertsDown(CopyArray(intArray), typeofArray);
     ChoiceUp(CopyArray(intArray), typeofArray);
     ChoiceDown(CopyArray(intArray), typeofArray);
     ShakerUp(CopyArray(intArray), typeofArray);
     ShakerDown(CopyArray(intArray), typeofArray);
     ShellUp(CopyArray(intArray), typeofArray);
     ShellDown(CopyArray(intArray), typeofArray);
 }
示例#7
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);
        }