static void Main(string[] args)
        {
            int[] numbers = { 8, 2, 4, 1, 3, 8 };
            var   sorter  = new CountingSort();

            sorter.Sort(numbers, 8);

            Console.WriteLine(string.Join(", ", numbers));
            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            int[] numbers = { 5, 1, 7, 2, 6, 4 };
            var   sorter  = new CountingSort();

            sorter.Sort(numbers, 7);

            foreach (var item in numbers)
            {
                System.Console.WriteLine(item);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            int[] numbers = {  };

            var sorter = new CountingSort();

            sorter.Sort(numbers);

            foreach (var number in numbers)
            {
                Console.WriteLine(number);
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            // CHALLENGE: Given an array of integers that fall within a bounded-range (like 1 to 100)
            //      and may include duplicates, sort the numbers.
            // ASSUMPTIONS: integers fall within a bounded-range. may include duplicates

            // SOLUTION: loop through array and tally the occurrence of each number, storing in a dictionary.
            //      then loop through the integers of the range and insert from the dictionary where applicable.
            //      - when a dictionary item has duplicates loop through those to insert as well.

            // for simplicity, example set sorts 1 - 20
            int[] numbers = new[] { 14, 18, 18, 17, 7, 13, 8, 13, 3, 4, 12, 8, 3, 11, 14, 15, 18, 15, 9, 10 };

            var sorted = CountingSort.Sort(numbers);

            foreach (var item in sorted)
            {
                Console.WriteLine(item);
            }
        }
        public static void Main(string[] args)
        {
            CountingSort cs      = new CountingSort();
            Random       randNum = new Random();
            var          watch   = new System.Diagnostics.Stopwatch();

            //int[] array = { 2, 3, 4, 1, 1, 4, 5 };
            int[] array = new int[1000000];

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = randNum.Next(0, 1000);
            }

            Console.WriteLine("Distribution Counting Sort");

            watch.Start();
            int[] sortedArray1 = cs.DistributionCountingSort(array);

            for (int i = 0; i < sortedArray1.Length; i++)
            {
                Console.Write(sortedArray1[i] + " ");
            }
            watch.Stop();
            Console.WriteLine($"\n\nExecution Time of Distribution Sort: {watch.ElapsedMilliseconds} ms\n\n\n");


            Console.WriteLine("Comparision Counting Sort");

            watch.Start();
            int[] sortedArray2 = cs.ComparisionCountingSort(array);

            for (int i = 0; i < sortedArray2.Length; i++)
            {
                Console.Write(sortedArray2[i] + " ");
            }
            watch.Stop();
            Console.WriteLine($"\n\nExecution Time of Comparision Sort: {watch.ElapsedMilliseconds} ms\n\n\n");
        }