public void RadixSort_Stress_Test()
        {
            int[] randomNumbers;
            int   nodeCount = 1000 * 1000;
            var   rnd       = new Random();

            randomNumbers = Enumerable.Range(1, nodeCount)
                            .OrderBy(x => rnd.Next())
                            .ToArray();

            var timer = new Stopwatch();

            timer.Start();

            var result = RadixSort.Sort(randomNumbers);

            timer.Stop();

            Debug.WriteLine($"sorted {nodeCount} integers using radix sort in {timer.ElapsedMilliseconds} milliseconds.");

            for (int i = 1; i <= nodeCount; i++)
            {
                Assert.AreEqual(i, result[i - 1]);
            }
        }
Пример #2
0
        public void InsertionSort_Test()
        {
            // Arrange
            var    collectionInsertion = new Collection <int>();
            var    collectionMerge     = new Collection <int>();
            var    collectionHeap      = new Collection <int>();
            var    collectionRadix     = new Collection <int>();
            Random random = new Random();

            // Act

            for (int i = 0; i < 1000; i++)
            {
                var number = random.Next(0, 10000);
                collectionInsertion.Add(number);
                collectionMerge.Add(number);
                collectionHeap.Add(number);
                collectionRadix.Add(number);
            }
            InsertionSort <int> .Sort(collectionInsertion);

            collectionMerge = MergeSort <int> .Sort(collectionMerge);

            HeapSort <int> .Sort(collectionHeap);

            RadixSort.Sort(collectionRadix);
            // Assert
            for (int i = 0; i < collectionInsertion.Count; i++)
            {
                Assert.AreEqual(collectionInsertion[i], collectionMerge[i]);
                Assert.AreEqual(collectionHeap[i], collectionMerge[i]);
                Assert.AreEqual(collectionRadix[i], collectionHeap[i]);
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            Console.Write("Введiть масив -> ");
            var oldArr = Console.ReadLine().Trim().Split(new char[] { ' ' }).Select(x => Convert.ToInt32(x)).ToArray();

            while (true)
            {
                Console.Write("1. Пiдрахунком\n2. За розрядами\n-> ");
                switch (Int32.Parse(Console.ReadLine()))
                {
                case 1:
                    var arr = CountingSort.Run(oldArr);
                    foreach (var item in arr)
                    {
                        Console.Write(item + " ");
                    }
                    Console.ReadLine();
                    break;

                case 2:
                    var arrRadix = RadixSort.Run(oldArr);
                    foreach (var item in arrRadix)
                    {
                        Console.Write(item + " ");
                    }
                    Console.ReadLine();
                    break;
                }
            }
        }
        private void btn123(object sender, EventArgs e)
        {
            switch ((sender as Button).Text)
            {
            case "Quick Sort Algorithm Simulation":
                QuickSort frmquick = new QuickSort();
                GlobalClass.CheckMdiChildren(frmquick);
                break;

            case "Counting Sort Algorithm Simulation":
                CountingSort frmcount = new CountingSort();
                GlobalClass.CheckMdiChildren(frmcount);
                break;

            case "Radix Sort Algorithm Simulation":
                RadixSort frmradix = new RadixSort();
                GlobalClass.CheckMdiChildren(frmradix);
                break;

            case "Dice Throw Problem":
                DiceThrow frmdicethrow = new DiceThrow();
                GlobalClass.CheckMdiChildren(frmdicethrow);
                break;

            case "Travelling Salesman Problem":
                TSP frmTSP = new TSP();
                GlobalClass.CheckMdiChildren(frmTSP);
                break;
            }
        }
Пример #5
0
        public void RadixSortLargeRandomArrayTest()
        {
            int[] arr =
            {
                8586,   4916,  5843,  4589,  4331,  9177, -6992,  8780,  8948, -4101, -8390,  8900,  3165, -5036,  5136,  -420,
                3868,   9700,  3924, -3041, -4483, -8856, -3565, -4697,  1812,  2103, -8455,  8361, -2569,  8488,  6245,  6304,
                -8980, -3969,  -422,  1273, -6731, -2400,  4409, -9780, -2776,  -533,  7970,  9449,  1908, -5483, -8328,  4147,
                4112,  -4641,  1730, -9490,  7088, -5676, -5217,  7442, -1519,   540, -7224, -7772,  7631, -5354,  1349, -9540,
                -347,  -4694,  7880, -2866,  5385, -6138, -3690, -3733, -4710,  3704,  9734,  6050, -6827, -3015,  3394, -2706,
                430,   -2602, -5751, -7929, -3243,  5735,  9215,  6695, -8753,  2135, -7208,  2729, -5177,  2181, -7412, -7423,
                8118,   7510,  -205, -3399
            };

            int[] expected =
            {
                -9780, -9540, -9490, -8980, -8856, -8753, -8455, -8390, -8328, -7929, -7772, -7423, -7412, -7224, -7208,
                -6992, -6827, -6731, -6138, -5751, -5676, -5483, -5354, -5217, -5177, -5036, -4710, -4697, -4694, -4641,
                -4483, -4101, -3969, -3733, -3690, -3565, -3399, -3243, -3041, -3015, -2866, -2776, -2706, -2602, -2569,
                -2400, -1519,  -533,  -422,  -420,  -347,  -205,   430,   540,  1273,  1349,  1730,  1812,  1908,  2103, 2135, 2181,
                2729,   3165,  3394,  3704,  3868,  3924,  4112,  4147,  4331,  4409,  4589,  4916,  5136,  5385,  5735, 5843, 6050,
                6245,   6304,  6695,  7088,  7442,  7510,  7631,  7880,  7970,  8118,  8361,  8488,  8586,  8780,  8900, 8948, 9177,
                9215,   9449,  9700, 9734
            };

            var sort   = new RadixSort();
            var result = sort.Sort(arr);

            Assert.AreEqual(expected, result);
        }
    SortingResult PerformRadixSort(float[] input)
    {
        Stopwatch stopWatch = new Stopwatch();

        stopWatch.Start();

        if (sort == null)
        {
            sort = new RadixSort();
            sort.SetupBuffers(input.Length, radixSortShader);
        }


        sort.Sort(input);
        sort.GetData(input);

        stopWatch.Stop();

        bool isSorted = RadixDemoUtilities.SortingCheck(input);


        return(new SortingResult()
        {
            sortingName = "Radix Sort",
            averageTimeTaken = stopWatch.ElapsedMilliseconds,
            isCorrectlySorted = isSorted,
            message = isSorted ? "" : "Wrongly sorted at: " + input.Length
        });
    }
Пример #7
0
        public void SortingTest()
        {
            Action <int[]>[] actions = new Action <int[]>[]
            {
                BubbleSort.Sort,
                data => BucketSort.Sort(data, SortingTests.MaxValue),
                data => CountingSort.Sort(data, SortingTests.MaxValue),
                HeapSort.Sort,
                InsertionSort.Sort,
                MergeSort.Sort,
                QuickSort.Sort,
                data => RadixSort.Sort(data, SortingTests.MaxValue),
            };

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    int[]   data    = ArrayUtilities.CreateRandomArray(j, 0, SortingTests.MaxValue);
                    int[][] results = new int[actions.Length][];

                    for (int k = 0; k < actions.Length; k++)
                    {
                        results[k] = new int[data.Length];
                        Array.Copy(data, results[k], data.Length);

                        actions[k](results[k]);
                        Assert.IsTrue(ArrayUtilities.AreEqual(results[k], results[0]));
                    }
                }
            }
        }
 //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";
     }
 }
Пример #9
0
        public static void CallRadixSort()
        {
            var arr = Program.arr;

            DispayArr(arr);
            RadixSort.CallRadixsort(arr, arr.Length);
            DispayArr(arr);
        }
Пример #10
0
    public static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

        RadixSort.Sort(input);

        Console.WriteLine(string.Join(" ", input));
    }
Пример #11
0
        private static void RadixSortTest()
        {
            var unsortedList = _testRunner.InitArray();
            var radixSort    = new RadixSort();
            var sortedList   = radixSort.Sort(unsortedList);

            Debug.Assert(_testRunner.Verify(sortedList));
        }
Пример #12
0
 static void Main(string[] args)
 {
     int[] arr = new int[] { 5, 2, 3, 8, 1, 2, 15, 23, 55, 66, 22, 15, 45 };
     arr.Write();
     RadixSort.Sort(arr);
     arr.Write();
     Console.ReadLine();
 }
Пример #13
0
        public void Sort()
        {
            int[]     arr       = new int[] { 170, 45, 75, 90, 802, 24, 2, 66 };
            int[]     resultArr = new int[] { 2, 24, 45, 66, 75, 90, 170, 802 };
            RadixSort radixSort = new RadixSort();

            radixSort.Sort(arr);
            Assert.Equal(resultArr, arr);
        }
Пример #14
0
 public void MSDDiffLengthTest()
 {
     string[] array = { "zoe", "alex", "luis", "ben", "johnny", "benny", "abbey", "shawn", "alice", "shirley", "john", "bobby", "cate" };
     RadixSort.MSD(array);
     for (int i = 0; i < array.Length; i++)
     {
         Assert.Equal(expectName[i], array[i]);
     }
 }
Пример #15
0
 public void MSDSameLengthTest()
 {
     string[] array = { "opq", "elk", "bcb", "bde", "exk", "aba", "bgp", "aac", "aaa", "cpd" };
     RadixSort.MSD(array);
     for (int i = 0; i < array.Length; i++)
     {
         Assert.Equal(expectSeq[i], array[i]);
     }
 }
Пример #16
0
        public void RadixSortTest()
        {
            // Arrange
            var input  = new int[] { 0, 15, 200, 3, 55555, 66666, 222, 888, 666, 9999, 12345893, 68478512, 6317521 };
            var actual = RadixSort.RaxdixSortAlgo(input);

            // Act & Assert
            actual.Should().BeInAscendingOrder();
        }
        public void RadixSort_Smoke_Test()
        {
            var result = RadixSort.Sort(TestArray);

            for (int i = 0; i < TestArray.Length; i++)
            {
                Assert.AreEqual(i, result[i]);
            }
        }
        public void RadixSort_Descending_Smoke_Test()
        {
            var result = RadixSort.Sort(testArray, SortDirection.Descending);

            for (int i = 0; i < testArray.Length; i++)
            {
                Assert.AreEqual(testArray.Length - i - 1, result[i]);
            }
        }
Пример #19
0
        public void SortWithEmptyArray()
        {
            int[]     arr       = new int[] {};
            int[]     resultArr = new int[] {};
            RadixSort radixSort = new RadixSort();

            radixSort.Sort(arr);

            Assert.Equal(resultArr, arr);
        }
        public void SortTest()
        {
            int[] array       = new int[] { 536, 484, 343, 287, 198 };
            var   sortedArray = new RadixSort().Sort(array);

            Assert.AreEqual(sortedArray.Length, array.Length);
            for (int i = 0; i < array.Length - 1; i++)
            {
                Assert.IsTrue(sortedArray[i].CompareTo(sortedArray[i + 1]) <= 0);
            }
        }
Пример #21
0
        public void RadixSortSimpleArrayTest()
        {
            int[] expected = { 10, 14, 22, 1000, 1500, 2000, 2001, 2002, 2003 };
            int[] arr      = { 22, 1500, 2001, 2002, 1000, 2000, 2003, 10, 14 };

            var sort = new RadixSort();

            var result = sort.Sort(arr);

            Assert.AreEqual(expected, result);
        }
Пример #22
0
        public void TestRadixSort()
        {
            var result = new int[_size];

            Array.Copy(_unsorted, result, _size);

            RadixSort.Sort(result, RadixSort.RadixSortType.Lsd);

            for (int i = 0; i < result.Length; i++)
            {
                Assert.AreEqual(_sorted[i], result[i]);
            }
        }
Пример #23
0
        public void WhenWeGiveArray_ThenItIsSorted()
        {
            int[] array = { 2, 4, 1, 5, 6, 8, 3, 9, 7 };

            RadixSort.Sort(array);
            int i = 1;

            foreach (int v in array)
            {
                Assert.AreEqual(i, v);
                i++;
            }
        }
Пример #24
0
        public SortingAlgorithmsBenchmark()
        {
            _collection = Generator.CreateRandomList(10000, 10000);

            _moveBasedInsertionSort = new MoveBasedInsertionSort <int>();
            _swapBaseInsertionSort  = new SwapBasedInsertionSort <int>();
            _mergeSourt             = new MergeSort <int>();
            _quickSort           = new QuickSort <int>();
            _randomizedQuickSort = new RandomizedQuickSort <int>();
            _countingSort        = new CountingSort();
            _radixSort           = new RadixSort();
            _heapSort            = new HeapSort <int>();
        }
Пример #25
0
        public void RadixSortTest()
        {
            int[] result = CreateResultArray();

            RadixSort sort = new RadixSort(result);

            result = sort.Sort();

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expected[i], result[i]);
            }
        }
Пример #26
0
        public void Test(int[] data)
        {
            // Arrange
            int[] data2 = new int[data.Length];
            Array.Copy(data, data2, data.Length);
            Array.Sort(data2);
            var sorter = new RadixSort();

            // Act
            sorter.Sort(data);

            // Assert
            CollectionAssert.AreEqual(data, data2);
        }
Пример #27
0
        public void RadixSortMSDTest()
        {
            // arrange
            var radixSort = new RadixSort <int>(Items);

            // act
            radixSort.Sort(false);

            // assert
            for (int i = 0; i < Items.Count; i++)
            {
                Assert.AreEqual(Sorted[i], radixSort.Items[i]);
            }
        }
        public void TestSortingULongsGeneric()
        {
            var ulongs = new List <ulong> {
                3, 5, 1, 8, 2
            };
            var radixSort = new RadixSort <ulong>(new Calculator <ulong>());

            ulongs = radixSort.Sort(ulongs);
            var expected = new List <ulong> {
                1, 2, 3, 5, 8
            };

            Assert.AreEqual(expected.Count, ulongs.Count);
            CollectionAssert.AreEqual(expected, ulongs);
        }
        public void TestSortingShortsGeneric()
        {
            var shorts = new List <short> {
                3, 5, 1, 8, 2
            };
            var radixSort = new RadixSort <short>(new Calculator <short>());

            shorts = radixSort.Sort(shorts);
            var expected = new List <short> {
                1, 2, 3, 5, 8
            };

            Assert.AreEqual(expected.Count, shorts.Count);
            CollectionAssert.AreEqual(expected, shorts);
        }
        public void TestSortingBytesGeneric()
        {
            var bytes = new List <byte> {
                3, 5, 1, 8, 2
            };
            var radixSort = new RadixSort <byte>(new Calculator <byte>());

            bytes = radixSort.Sort(bytes);
            var expected = new List <byte> {
                1, 2, 3, 5, 8
            };

            Assert.AreEqual(expected.Count, bytes.Count);
            CollectionAssert.AreEqual(expected, bytes);
        }