예제 #1
0
        private void CocktailSortButton_Click(object sender, EventArgs e)
        {
            CleaningLabels();
            var cocktail = new CocktailSort <SortedItem>(items);

            BtnClick(cocktail);
        }
예제 #2
0
        public void CocktailSort()
        {
            var algorithm    = new CocktailSort();
            var sortedVector = algorithm.Sort(DataDefinition.UnsortedVector());

            Assert.Equal(DataDefinition.SortedVector, sortedVector);
        }
 //This will show how the num list runs on each algorithm
 //This allows the user to compare them
 public void hitSpeedCompButton()
 {
     algView = !algView;            //Change whether you are looking at the algorithm or speed comparison
     if (algView)                   //If you are now viewing at the algorithm pseudocode
     {
         algText.text = oldAlgText; //Change the text back to the pseudocode
         if (!half)
         {
             algDescription.enabled = true;
         }
         speedCompText.text = "Speed Comparison";
     }
     else//Otherwise display the speed comparison
     {
         oldAlgText = algText.text;
         string storageText = "Bubble Sort:{0} μs\nCocktail Sort: {1} μs\nComb Sort: {2} μs\nHeap Sort: {3}" +
                              " μs\nInsertion Sort: {4} μs\nMerge Sort:{5} μs\nQuick Sort:{6} μs\nShell Sort:{7} μs\nFlash Sort:{8} μs" +
                              "\nBucket Sort:{9} μs\nRadix Sort:{10} μs";
         //Format the text to show each element in microseconds
         algText.text = string.Format(storageText, BubbleSort.BubbleSortTime(new List <int>(copy)),
                                      CocktailSort.CocktailSortTime(new List <int>(copy)), CombSort.CombSortTime(new List <int>(copy)),
                                      HeapSort.HeapSortStartTime(new List <int>(copy)), InsertionSort.InsertionSortTime(new List <int>(copy)),
                                      Mergesort.MergeSortTime(new List <int>(copy), 0, copy.Count - 1), QuickSort.QuickSortStartTime(new List <int>(copy), 0, copy.Count - 1),
                                      ShellSort.ShellSortTime(new List <int>(copy)), FlashSort.FlashSortTime(new List <int>(copy)), BucketSort.BucketSortTime(new List <int>(copy), 34)
                                      , RadixSort.RadixSortTime(new List <int>(copy)));
         algDescription.enabled = false;
         speedCompText.text     = "Algorithm";
     }
 }
예제 #4
0
        static void ConstantTableTest()
        {
            //tworzenie tablicy bazowej - wypełninonej zerami
            int[] _oBaseTable = new int[g_iBaseTabSize];

            //tworzenie obiektów sortujących
            SelectionSort selectionSort = new SelectionSort(_oBaseTable);
            InsertionSort insertionSort = new InsertionSort(_oBaseTable);
            CocktailSort  cocktailSort  = new CocktailSort(_oBaseTable);
            HeapSort      heapSort      = new HeapSort(_oBaseTable);

            //pętla po typach algoryutmów sortujących
            for (int type = 0; type < 4; type++)
            {
                //wypisanie informacji dla każdego typu algorytmu
                switch (type)
                {
                case 0:
                    Console.WriteLine("SelectionSort");
                    break;

                case 1:
                    Console.WriteLine("InsertionSort");
                    break;

                case 2:
                    Console.WriteLine("CocktailSort");
                    break;

                case 3:
                    Console.WriteLine("HeapSort");
                    break;
                }

                //główna pętla wielkości sortowanych tablic
                for (int i = 50_000; i <= g_iBaseTabSize; i += 5_000)
                {
                    //określa który algorytm ma sortować
                    switch (type)
                    {
                    case 0:
                        selectionSort.MeasureSortTime(i);
                        break;

                    case 1:
                        insertionSort.MeasureSortTime(i);
                        break;

                    case 2:
                        cocktailSort.MeasureSortTime(i);
                        break;

                    case 3:
                        heapSort.MeasureSortTime(i);
                        break;
                    }
                }
            }
        }
예제 #5
0
        public void Cocktail_Sort_Test()
        {
            var            sequence      = new[] { 1, 9, 3, 7, 2, 6, 11, 14, 10, 6, 8, 19, 22 };
            ISortAlgorithm sortAlgorithm = new CocktailSort(sequence);

            sortAlgorithm.SortSequence();
            sortAlgorithm.SortedSequence.SequenceEqual(new[] { 1, 2, 3, 6, 6, 7, 8, 9, 10, 11, 14, 19, 22 })
            .Should().BeTrue();
        }
예제 #6
0
        public void SortTestCocktail()
        {
            CocktailSort <Int32> cocktail = new CocktailSort <Int32>();

            cocktail.Items.AddRange(list);

            cocktail.Sort();

            for (Int32 i = 0; i < sorted.Length; i++)
            {
                Assert.AreEqual(sorted[i], cocktail.Items[i]);
            }
        }
예제 #7
0
파일: SortTest.cs 프로젝트: ko4a/Sorter
        public void CocktailSortTest()
        {
            var cocktail = new CocktailSort <int>();

            cocktail.Items.AddRange(items);

            cocktail.Sort();

            for (int i = 0; i < 10_000; i++)
            {
                Assert.AreEqual(sorted[i], cocktail.Items[i]);
            }
        }
예제 #8
0
        public void CocktailSortTest()
        {
            //arrange
            var cocktailSort = new CocktailSort <int>(dataList, "Cocktail");

            //act
            cocktailSort.Sort();
            //assert
            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(sortedItems[i], cocktailSort.Items[i]);
            }
        }
예제 #9
0
        public void CocktailSortTest()
        {
            // arrange
            var cocktail = new CocktailSort <int>();

            cocktail.Items.AddRange(Items);
            // act
            cocktail.Sort();
            // assert
            for (int i = 0; i < cocktail.Items.Count; i++)
            {
                Assert.AreEqual(Sorted[i], cocktail.Items[i]);
            }
        }
예제 #10
0
        public void CocktailSortTest()
        {
            // arrange
            AlgorithmBase <int> cocktail = new CocktailSort <int>(items);

            // act
            cocktail.SortAndGetSpan();

            // assert
            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(sorted[i], cocktail.Items[i]);
            }
        }
예제 #11
0
        public void CocktailSortTest()
        {
            //Act
            var cocktail = new CocktailSort <int>();

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

            //Assert
            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(items[i], cocktail.Items[i]);
            }
        }
예제 #12
0
 private void CocktailSortButtonClick(object sender, EventArgs e)
 {
     if (progressBarCount < 2)
     {
         MessageBox.Show("нечего сортировать");
     }
     else
     {
         var cocktail = new CocktailSort <int>();
         cocktail.Items.AddRange(values.Select(x => x.Bar.Value));
         cocktail.SwapEvent += SwapEvent;
         var time = cocktail.Sort();
         ShowInfoAboutSort(cocktail, time);
     }
 }
예제 #13
0
 private void CocktailSortButton_Click(object sender, EventArgs e)
 {
     if (Collection.Count < 10001)
     {
         CocktailLabel.Text = "Time: ";
         var cocktail = new CocktailSort <int>(Collection, "CocktailSort");
         cocktail.Sort();
         DisplayInfoFromSort(cocktail);
         CocktailLabel.Text += cocktail.Time.ToString();
     }
     else
     {
         CocktailLabel.Text = "To much for it ...";
     }
 }
예제 #14
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}";
        }
예제 #15
0
 public void Initialize()
 {
     Sorter = new CocktailSort();
 }
예제 #16
0
        private void cocktailSortButton_Click(object sender, EventArgs e)
        {
            var cocktail = new CocktailSort <SortedItem>(items);

            BtnSortClick(cocktail);
        }
예제 #17
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();
        }