예제 #1
0
        public int[] Algorithm(int[] mas, bool flag = true)
        {
            if (flag)
            {
                IOFile.FillContent();
                System.Diagnostics.Stopwatch myStopwatch = new System.Diagnostics.Stopwatch();
                myStopwatch.Start();


                ArrayList[] lists = new ArrayList[10];
                for (int i = 0; i < 10; ++i)
                {
                    lists[i] = new ArrayList();
                }

                {
                    for (int step = 0; step < 3; ++step)
                    {
                        for (int i = 0; i < mas.Length; ++i)
                        {
                            int temp = (mas[i] % (int)Math.Pow(10, step + 1)) /
                                       (int)Math.Pow(10, step);
                            lists[temp].Add(mas[i]);
                        }
                        int k = 0;
                        for (int i = 0; i < 10; ++i)
                        {
                            for (int j = 0; j < lists[i].Count; ++j)
                            {
                                mas[k++] = (int)lists[i][j];
                            }
                        }
                        for (int i = 0; i < 10; ++i)
                        {
                            lists[i].Clear();
                        }
                    }
                }
                myStopwatch.Stop();
                var    resultTime  = myStopwatch.Elapsed;
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}:{3:000}",
                                                   resultTime.Hours,
                                                   resultTime.Minutes,
                                                   resultTime.Seconds,
                                                   resultTime.Milliseconds);
                Analytic.timeRank       += (resultTime.Milliseconds) + (resultTime.Seconds * 1000) + (resultTime.Minutes * 100000);
                Analytic.timeRankformore = (resultTime.Milliseconds) + (resultTime.Seconds * 1000) + (resultTime.Minutes * 100000);



                Analytic.forRankSorting   = elapsedTime;
                Analytic.timeforRank     += elapsedTime + ", ";
                Analytic.timeforRanktimet = elapsedTime;
            }
            return(mas);
        }
예제 #2
0
        public int[] Algorithm(int[] mas, bool flag = true)
        {
            if (flag)
            {
                IOFile.FillContent();
                System.Diagnostics.Stopwatch myStopwatch = new System.Diagnostics.Stopwatch();
                myStopwatch.Start();
                //О Т С Ю Д А    Н А Д О    В С Е    М Е Н Я Т Ь ! ! !
                int newElement, location;

                for (int i = 1; i < mas.Length; i++)
                {
                    newElement = mas[i];



                    location = i - 1;

                    this.iterationCount++;
                    IOFile.Content += this.iterationCount.ToString() + " итерация: " + '\n';
                    IOFile.InputInfoAboutComparison(mas[i], mas[location]);
                    ComparativeAnalysis.Comparison++;

                    while (location >= 0 && mas[location] > newElement)
                    {
                        IOFile.InputInfoAboutTransposition(mas[i], mas[location]);

                        ComparativeAnalysis.NumberOfPermutations++;
                        IOFile.FillContent();
                        form1.AddItemsListBox(mas[i], mas[location]);
                        mas[location + 1] = mas[location];
                        location          = location - 1;
                    }
                    mas[location + 1] = newElement;
                }
                myStopwatch.Stop();
                var    resultTime = myStopwatch.Elapsed;
                string elapsedTim = String.Format("{0:00}:{1:00}:{2:00}:{3:000}",
                                                  resultTime.Hours,
                                                  resultTime.Minutes,
                                                  resultTime.Seconds,
                                                  resultTime.Milliseconds);



                form1.labelCountComparison.Text      = Convert.ToString(ComparativeAnalysis.Comparison);
                form1.labelNumberOfPermutations.Text = Convert.ToString(ComparativeAnalysis.NumberOfPermutations);
                form1.labelTimeSort.Text             = elapsedTim;

                Analytic.forInsert = "Ср:" + Convert.ToString(ComparativeAnalysis.Comparison) +
                                     "\nПе:" + Convert.ToString(ComparativeAnalysis.NumberOfPermutations) + "\nВр:";
                Analytic.numberofperInsert = Convert.ToString(ComparativeAnalysis.NumberOfPermutations);
            }
            return(mas);
        }
예제 #3
0
        public int[] Algorithm(int[] mas, bool flag = true)
        {
            if (flag)
            {
                IOFile.FillContent();
                System.Diagnostics.Stopwatch myStopwatch = new System.Diagnostics.Stopwatch();
                myStopwatch.Start();


                ArrayList[] lists = new ArrayList[10];
                for (int i = 0; i < 10; ++i)
                {
                    lists[i] = new ArrayList();
                }

                {
                    for (int step = 0; step < 3; ++step)
                    {
                        for (int i = 0; i < mas.Length; ++i)
                        {
                            this.iterationCount++;
                            IOFile.Content += this.iterationCount.ToString() + " итерация: " + '\n';
                            IOFile.InputInfoAboutComparison(mas[step], mas[i]);
                            ComparativeAnalysis.Comparison++;

                            int temp = (mas[i] % (int)Math.Pow(10, step + 1)) /
                                       (int)Math.Pow(10, step);
                            lists[temp].Add(mas[i]);
                        }
                        int k = 0;
                        for (int i = 0; i < 10; ++i)
                        {
                            for (int j = 0; j < lists[i].Count; ++j)
                            {
                                mas[k++] = (int)lists[i][j];
                                IOFile.InputInfoAboutTransposition(mas[i], mas[j]);

                                ComparativeAnalysis.NumberOfPermutations++;
                                IOFile.FillContent();
                                form1.AddItemsListBox(mas[i], mas[j]);
                            }
                        }
                        for (int i = 0; i < 10; ++i)
                        {
                            lists[i].Clear();
                        }
                    }
                }
                myStopwatch.Stop();
                var    resultTime  = myStopwatch.Elapsed;
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}:{3:000}",
                                                   resultTime.Hours,
                                                   resultTime.Minutes,
                                                   resultTime.Seconds,
                                                   resultTime.Milliseconds);


                form1.labelCountComparison.Text      = Convert.ToString(ComparativeAnalysis.Comparison);
                form1.labelNumberOfPermutations.Text = Convert.ToString(ComparativeAnalysis.NumberOfPermutations);
                form1.labelTimeSort.Text             = elapsedTime;

                Analytic.forRankSorting = "Ср:" + Convert.ToString(ComparativeAnalysis.Comparison) +
                                          "\nПе:" + Convert.ToString(ComparativeAnalysis.NumberOfPermutations) + "\nВр:";
                Analytic.numberofperRank = Convert.ToString(ComparativeAnalysis.NumberOfPermutations);
            }
            return(mas);
        }