public void GnomeSort()
        {
            var algorithm    = new GnomeSort();
            var sortedVector = algorithm.Sort(DataDefinition.UnsortedVector());

            Assert.Equal(DataDefinition.SortedVector, sortedVector);
        }
示例#2
0
        private void GnomeSortButton_Click(object sender, EventArgs e)
        {
            CleaningLabels();
            var gnome = new GnomeSort <SortedItem>(items);

            BtnClick(gnome);
        }
示例#3
0
        static void Main(string[] args)
        {
            Random r = new Random();
            int size = r.Next(100, 100);
            var sortable = new List<int>();
            Stopwatch timer = new Stopwatch();

            for (int i = 0; i < size; i++)
            {
                sortable.Add(r.Next(-230, 26));
            }

            var algorithm = new GnomeSort<int>();

            timer.Start();
            algorithm.Sort(sortable);
            timer.Stop();

            TimeSpan time = timer.Elapsed;

            string elapsedTime = String.Format("{0:00}.{1:00}", time.Seconds, time.Milliseconds / 10);

            Console.WriteLine("GnomeSort runtime = " + elapsedTime + "\n");

            Console.WriteLine("Result:");
            foreach (var res in sortable)
            {
                Console.WriteLine(res);
            }

            Console.ReadLine();
        }
示例#4
0
        public void SortTest(double[] array, double[] result)
        {
            var gnomeSort  = new GnomeSort();
            var bubbleSort = new BubbleSort();

            double[] testGnomeResult  = gnomeSort.Sort(array);
            double[] testBubbleResult = bubbleSort.Sort(array);
            Assert.AreEqual(testBubbleResult, result);
            Assert.AreEqual(testGnomeResult, result);
        }
示例#5
0
        public void GnomeSort()
        {
            var gnome = new GnomeSort <int>();

            gnome.Items.AddRange(items);
            gnome.Sort();
            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(sorted[i], gnome.Items[i]);
            }
        }
示例#6
0
        public void QuickSortTest()
        {
            int[] array  = new int[] { 6, 11, 1, 8, 2, 16, 18, 4, 10, 7, 17, 15, 12, 9, 14, 3, 13, 5 };
            int[] array2 = new int[] { 6, 11, 1, 8, 2, 16, 18, 4, 10, 7, 17, 15, 12, 9, 14, 3, 13, 5 };
            int[] array3 = new int[] { 6, 11, 1, 8, 2, 16, 18, 4, 10, 7, 17, 15, 12, 9, 14, 3, 13, 5 };
            int[] array4 = new int[] { 6, 11, 1, 8, 2, 16, 18, 4, 10, 7, 17, 15, 12, 9, 14, 3, 13, 5 };

            var test  = new QuickSort().GetSortOne(array);
            var test2 = new QuickSort().GetSortTwo(array);
            var test3 = new GnomeSort().GetSort(array2);
            var test4 = new GnomeSort().GetSortOptimize(array3);
            var test5 = new InsertionSort().GetSort(array4);
        }
        public void GnomeSortTest()
        {
            //arrange
            var gnome = new GnomeSort <int>(dataList, "Gnome");

            //act
            gnome.Sort();
            //assert
            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(sortedItems[i], gnome.Items[i]);
            }
        }
示例#8
0
        public void GnomeSortTest()
        {
            int[] result = CreateResultArray();

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

            result = sort.Sort();

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expected[i], result[i]);
            }
        }
示例#9
0
        public void GnomeSortTest()
        {
            // arrange
            AlgorithmBase <int> gnome = new GnomeSort <int>(items);

            // act
            gnome.SortAndGetSpan();

            // assert
            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(sorted[i], gnome.Items[i]);
            }
        }
示例#10
0
        public void GnomeSortTest()
        {
            // arrange
            var gnome = new GnomeSort <int>();

            gnome.Items.AddRange(Items);
            // act
            gnome.Sort();
            // assert
            for (int i = 0; i < gnome.Items.Count; i++)
            {
                Assert.AreEqual(Sorted[i], gnome.Items[i]);
            }
        }
示例#11
0
 private void GnomeSortButton_Click(object sender, EventArgs e)
 {
     if (Collection.Count < 10001)
     {
         GnomeLabel.Text = "Time: ";
         var Gnome = new GnomeSort <int>(Collection, "GnomeSort");
         Gnome.Sort();
         DisplayInfoFromSort(Gnome);
         GnomeLabel.Text += Gnome.Time.ToString();
     }
     else
     {
         GnomeLabel.Text = "To much for it ...";
     }
 }
示例#12
0
        public void GnomeSortTest()
        {
            //Act
            var gnome = new GnomeSort <int>();

            gnome.Items.AddRange(items);
            gnome.Sort();
            items.Sort();

            //Assert
            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(items[i], gnome.Items[i]);
            }
        }
示例#13
0
        public void Run()
        {
            int[]           iArrary = new int[] { 1, 5, 13, 6, 10, 55, 99, 2, 87, 12, 34, 75, 33, 47 };
            GnomeSort       gs      = new GnomeSort();
            InsertionSorter ii      = new InsertionSorter();
            BubbleSorter    bs      = new BubbleSorter();
            SelectionSorter ss      = new SelectionSorter();
            ShellSorter     sh      = new ShellSorter();

            gs.Sort(iArrary);
            for (int m = 0; m < iArrary.Length; m++)
            {
                Console.Write("{0} ", iArrary[m]);
            }
            Console.WriteLine();

            Console.ReadKey();
        }
示例#14
0
        static void Main(string[] args)
        {
            Stopwatch watch = new Stopwatch();

            List<char> mainList = new List<char>();
            Random x = new Random();
            for (int i = 0; i < 100000; i++)
            {
                mainList.Add((char)x.Next(97,122));
            }

            Console.WriteLine("Selection Sort: ");
            SelectionSort s = new SelectionSort();
            TimeSpan selectionTime;
            watch.Start();
            List<char> selectionList = s.Sort<List<char>, char>(mainList, Comparer<char>.Default);
            watch.Stop();
            selectionTime = watch.Elapsed;
            string selectionElapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", selectionTime.Hours, selectionTime.Minutes, selectionTime.Seconds, selectionTime.Milliseconds / 10);
            Console.WriteLine("\nTime " + selectionElapsedTime + "\n");
            watch.Reset();

            Console.WriteLine("Gnome Sort: ");
            GnomeSort g = new GnomeSort();
            TimeSpan gnomeTime;
            watch.Start();
            List<char> gnomeList = s.Sort<List<char>, char>(mainList, Comparer<char>.Default);
            watch.Stop();
            gnomeTime = watch.Elapsed;
            string gnomeElapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", gnomeTime.Hours, gnomeTime.Minutes, gnomeTime.Seconds, gnomeTime.Milliseconds / 10);
            Console.WriteLine("\nTime " + gnomeElapsedTime + "\n");
            watch.Reset();

            Console.WriteLine("Comb Sort: ");
            SelectionSort c = new SelectionSort();
            TimeSpan combTime;
            watch.Start();
            List<char> combList = s.Sort<List<char>, char>(mainList, Comparer<char>.Default);
            watch.Stop();
            combTime = watch.Elapsed;
            string combElapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", combTime.Hours, combTime.Minutes, combTime.Seconds, combTime.Milliseconds / 10);
            Console.WriteLine("\nTime " + combElapsedTime + "\n");
            watch.Reset();
        }
示例#15
0
 public void Initialize()
 {
     Sorter = new GnomeSort();
 }
示例#16
0
        private void AllSortButton_Click(object sender, EventArgs e)
        {
            SortDatarichTextBox.Text = "Calculating ... Wait a moment ...";
            BubbleLabel.Text         = "Time: ";
            SelectionLabel.Text      = "Time: ";
            CocktailLabel.Text       = "Time: ";
            GnomeLabel.Text          = "Time: ";
            HeapLabel.Text           = "Time: ";
            InsertionLabel.Text      = "Time: ";
            LSDLabel.Text            = "Time: ";
            MSDLabel.Text            = "Time: ";
            MergeLabel.Text          = "Time: ";
            QuickLabel.Text          = "Time: ";
            ShellLabel.Text          = "Time: ";
            TreeLabel.Text           = "Time: ";
            SortDatarichTextBox.Text = "";
            var min = new List <BaseAlgorithm <int> >();

            if (Collection.Count < 10001)
            {
                var bubble = new BubbleSort <int>(Collection, "BubbleSort");
                bubble.Sort();
                BubbleLabel.Text += bubble.Time.ToString();
                min.Add(bubble);
            }
            if (Collection.Count < 10001)
            {
                var selection = new SelectionSort <int>(Collection, "SelectionSort");
                selection.Sort();
                SelectionLabel.Text += selection.Time.ToString();
                min.Add(selection);
            }
            if (Collection.Count < 10001)
            {
                var cocktail = new CocktailSort <int>(Collection, "CocktailSort");
                cocktail.Sort();
                CocktailLabel.Text += cocktail.Time.ToString();
                min.Add(cocktail);
            }
            if (Collection.Count < 10001)
            {
                var Gnome = new GnomeSort <int>(Collection, "GnomeSort");
                Gnome.Sort();
                GnomeLabel.Text += Gnome.Time.ToString();
                min.Add(Gnome);
            }
            if (Collection.Count < 10001)
            {
                var Insertion = new InsertionSort <int>(Collection, "InsertionSort");
                Insertion.Sort();
                InsertionLabel.Text += Insertion.Time.ToString();
                min.Add(Insertion);
            }
            var Tree = new TreeSort <int>(Collection, "TreeSort");

            Tree.Sort();
            TreeLabel.Text += Tree.Time.ToString();
            min.Add(Tree);
            var Heap = new HeapSort <int>(Collection, "HeapSort");

            Heap.Sort();
            HeapLabel.Text += Heap.Time.ToString();
            min.Add(Heap);
            var LSDRadix = new LSDRadixSort <int>(Collection, "LSDRadixSort");

            LSDRadix.Sort();
            LSDLabel.Text += LSDRadix.Time.ToString();
            min.Add(LSDRadix);
            var MSDRadix = new MSDRadixSort <int>(Collection, "MSDRadixSort");

            MSDRadix.Sort();
            MSDLabel.Text += MSDRadix.Time.ToString();
            min.Add(MSDRadix);
            var Merge = new MergeSort <int>(Collection, "MergeSort");

            Merge.Sort();
            MergeLabel.Text += Merge.Time.ToString();
            min.Add(Merge);
            var Quick = new QuickSort <int>(Collection, "QuickSort");

            Quick.Sort();
            QuickLabel.Text += Quick.Time.ToString();
            min.Add(Quick);
            var Shell = new ShellSort <int>(Collection, "ShellSort");

            Shell.Sort();
            ShellLabel.Text += Shell.Time.ToString();
            min.Add(Shell);
            var best = GetMinTime(min);

            SortDatarichTextBox.Text = $"THE BEST:\n" + best.Name + $"\n{best.Time}";
        }
示例#17
0
 public void GnomeSetUp()
 {
     Sorter = new GnomeSort();
 }
示例#18
0
        static void Main(string[] args)
        {
            int[] arr = new int[10000];
            Random rnd = new Random();
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(10000);
            }
            ISort<int> s = new BubbleSort<int>();
            DateTime dt = DateTime.Now;
            arr = s.Sorting(arr);
            Console.WriteLine("Time for BubbleSort is {0}.", DateTime.Now - dt);

            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(10000);
            }
            dt = DateTime.Now;
            s = new CocktailSort<int>();
            arr = s.Sorting(arr);
            Console.WriteLine("Time for CocktailSort is {0}.", DateTime.Now - dt);

            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(10000);
            }
            dt = DateTime.Now;
            s = new EvenOddSort<int>();
            arr = s.Sorting(arr);
            Console.WriteLine("Time for EvenOddSort is {0}.", DateTime.Now - dt);

            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(10000);
            }
            dt = DateTime.Now;
            s = new CombSort<int>();
            arr = s.Sorting(arr);
            Console.WriteLine("Time for CombSort is {0}.", DateTime.Now - dt);

            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(10000);
            }
            dt = DateTime.Now;
            s = new GnomeSort<int>();
            arr = s.Sorting(arr);
            Console.WriteLine("Time for GnomeSort is {0}.", DateTime.Now - dt);

            arr = new int[10000];
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(10000);
            }
            dt = DateTime.Now;
            s = new InsertionSort<int>();
            arr = s.Sorting(arr);
            Console.WriteLine("Time for InsertionSort is {0}.", DateTime.Now - dt);

            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(10000);
            }
            dt = DateTime.Now;
            s = new BinaryInsertionSort<int>();
            arr = s.Sorting(arr);
            Console.WriteLine("Time for BinaryInsertionSort is {0}.", DateTime.Now - dt);

            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(10000);
            }
            dt = DateTime.Now;
            s = new ShellSort<int>();
            arr = s.Sorting(arr);
            Console.WriteLine("Time for ShellSort is {0}.", DateTime.Now - dt);

            arr = new int[1000000];
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(1000000);
            }
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(10000);
            }
            dt = DateTime.Now;
            s = new HeapSort<int>();
            arr = s.Sorting(arr);
            Console.WriteLine("Time for HeapSort is {0}.", DateTime.Now - dt);
            int ddd = 0;
            for (int i = 0; i < arr.Length - 2; i++)
            {
                //Console.Write(arr[i] + " ");
                if (arr[i] > arr[i + 1]) //Console.WriteLine("Fatal ERROR!!!");
                    ddd++;
            }
            Console.WriteLine("Error count: {0}", ddd);

            dt = DateTime.Now;
            s = new MergeSort<int>();
            arr = s.Sorting(arr);
            Console.WriteLine("Time for MergeSort is {0}.", DateTime.Now - dt);

            //StreamWriter sw = new StreamWriter("C:/Users/suvorovi/1.txt");
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(1000000);
                //sw.Write(arr[i] + " ");
            }
            //sw.WriteLine("");
            dt = DateTime.Now;
            s = new QuickSort<int>();
            arr = s.Sorting(arr);
            Console.WriteLine("Time for QuickSort is {0}.", DateTime.Now - dt);
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rnd.Next(1000000);
                //sw.Write(arr[i] + " ");
            }
            //sw.WriteLine("");
            dt = DateTime.Now;
            s = new TimSort<int>();
            arr = s.Sorting(arr);
            Console.WriteLine("Time for TimSort is {0}.", DateTime.Now - dt);
            ddd = 0;
            for (int i = 0; i < arr.Length - 2; i++)
            {
                //Console.Write(arr[i] + " ");
                if (arr[i] > arr[i + 1]) //Console.WriteLine("Fatal ERROR!!!");
                    ddd++;
            }
            Console.WriteLine("Error count: {0}", ddd);
            Console.ReadLine();
            //sw.Close();
        }
示例#19
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]);
                }
            }
        }
示例#20
0
        private void GnomeSortButton_Click(object sender, EventArgs e)
        {
            var gnome = new GnomeSort <SortedItem>(items);

            BttnSort_Click(gnome);
        }