Пример #1
0
        static void Main(string[] args)
        {
            List<int> list = new List<int>();

            Random rand = new Random();

            for (int i = 0; i < 100000; i++ )
            {
                list.Add(rand.Next(-500,500));
            }

            List<ISorting> sortings = new List<ISorting>();
            HeapSort heapSort = new HeapSort();
            sortings.Add(heapSort);
            CoctailSort coctailSort = new CoctailSort();
            sortings.Add(coctailSort);
            ShellSort shellSort = new ShellSort();
            sortings.Add(shellSort);

            string[] name = new string[] { "heapsort", "coctailsort", "shellsort" };
            int num = 0;
            foreach (ISorting i in sortings)
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                i.Sort<List<int>, int>(list);
                stopWatch.Stop();
                Console.WriteLine("Time of {0} sort = {1}", name[num], stopWatch.Elapsed);
                num++;
            }

            Console.ReadKey();
        }
Пример #2
0
        public void SortTest()
        {
            // Arrange
            var coctail = new CoctailSort <int>();

            var rnd   = new Random();
            var items = new List <int>();

            for (var i = 0; i < 10000; i++)
            {
                items.Add(rnd.Next(0, 100));
            }

            coctail.Items.AddRange(items);
            var sorted = items.OrderBy(x => x).ToArray();

            // Act
            coctail.Sort();


            // Assert
            for (var i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(sorted[i], coctail.Items[i]);
            }
        }
Пример #3
0
        public void CoctailSortTest()
        {
            var coctail = new CoctailSort <int>();

            coctail.Items.AddRange(items);
            coctail.Sort();
            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(sorted[i], coctail.Items[i]);
            }
        }
Пример #4
0
        public void CocktailSortTest()
        {
            int[] result = CreateResultArray();

            CoctailSort <int> sort = new CoctailSort <int>(result);

            result = sort.Sort();

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expected[i], result[i]);
            }
        }
Пример #5
0
        public void CoctailSortTest()
        {
            // Arrange
            var coctail = new CoctailSort <int>();

            coctail.Items.AddRange(Items);

            // Act
            coctail.Sort();

            // Assest
            for (int i = 0; i < Items.Count; i++)
            {
                Assert.AreEqual(Sorted[i], coctail.Items[i]);
            }
        }
Пример #6
0
        public void SortTest()
        {
            //arrange
            var rnd        = new Random();
            var collection = new List <int>();
            var coctail    = new CoctailSort <int>();

            for (int i = 0; i < 10; i++)
            {
                collection.Add(rnd.Next(0, 100));
            }
            coctail.Items.AddRange(collection);
            collection.Sort();

            //act
            coctail.Sort();

            //arrange

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(collection[i], coctail.Items[i]);
            }
        }
Пример #7
0
        private async void Button3_Click(object sender, EventArgs e)
        {
            AlgorithmsBase <int> algorithmsBase = null;
            var Items     = new List <int>();
            var timeSpan  = new List <TimeSpan>();
            var swapCount = new List <int>();

            richTextBoxParser(Items);

            #region Методы для вычисления сортировок.

            algorithmsBase = new BubbleSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.BubbleSort, timeSpan[0], swapCount[0]);
            }
                                                     ));

            algorithmsBase = new CoctailSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.CoctailSort, timeSpan[1], swapCount[1]);
            }
                                                     ));

            algorithmsBase = new InsertSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.InsertionSort, timeSpan[2], swapCount[2]);
            }
                                                     ));

            algorithmsBase = new ShellSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.ShellSort, timeSpan[3], swapCount[3]);
            }
                                                     ));

            algorithmsBase = new HeapSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.HeapSort, timeSpan[4], swapCount[4]);
            }
                                                     ));

            algorithmsBase = new TreeSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.TreeSort, timeSpan[5], swapCount[5]);
            }
                                                     ));

            algorithmsBase = new SelectionSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.SelectionSort, timeSpan[6], swapCount[6]);
            }
                                                     ));

            algorithmsBase = new GnomeSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.GnomeSort, timeSpan[7], swapCount[7]);
            }
                                                     ));

            algorithmsBase = new MergeSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.MergeSort, timeSpan[8], swapCount[8]);
            }
                                                     ));

            algorithmsBase = new QuickSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.QuickSort, timeSpan[9], swapCount[9]);
            }
                                                     ));

            #endregion

            button3.Enabled = false;

            string[] seriesArray = new string[10];
            int[]    pointsArray = new int[10];

            chart1.Series.Clear();
            var countSeries = 0;
            checkBoxCheckedAll(ref countSeries, seriesArray, pointsArray, swapCount);
            chartDefaultSettings(countSeries, pointsArray.Max());

            for (int i = 0; i < seriesArray.Length; i++)
            {
                if (seriesArray[i] != null)
                {
                    Series series = chart1.Series.Add(seriesArray[i]);
                    series.Points.Add(pointsArray[i]);
                }
            }
        }