Example #1
0
        /// <summary>
        /// Perform a frequency sort on the given array, with the given value being the number of different items in that array
        /// </summary>
        /// <param name="toSort">The array to be sorted.</param>
        /// <param name="counterSize">The number of different values in the array; e.g. ASCII is 0-255, so counterSize = 255.</param>
        /// <returns>Returns a measure of the operations performed by the sort.</returns>
        private static int FrequencySortCount(int[] toSort, int counterSize)
        {
            int logCount = 0;

            int[] frequencyCount = new int[counterSize];

            Common_Code.Populate(frequencyCount, 0);

            // Increment the counter at the index of the ASCII value by 1 and increment log count by 1 since we performed an operation
            for (int i = 0; i < toSort.Length; i++)
            {
                frequencyCount[toSort[i]]++;
                logCount++;
            }

            // I think this should work, test and stuff
            logCount += FrequencySortToFile(frequencyCount, toSort.Length);

            return(logCount);
        }