Answered step by step
Verified Expert Solution
Question
1 Approved Answer
use c++, sortnums.txt 20 16 76 26 33 4 16 19 8 64 76 80 28 28 98 2 3 19 48 27 Counting sort
use c++,
sortnums.txt
20
16
76
26
33
4
16
19
8
64
76
80
28
28
98
2
3
19
48
27
Counting sort is a sorting algorithm that is elegant in its simplicity. It uses a single pass through an array of numbers, counting how many instances of each unique number appear. The good: it's a fast sort, O(n). The not-so-good: to use it, we have to know the range of numbers we're sorting, for example, O- 100. The algorithm itself is only a few lines and uses a set of counters, one for each number. Given an array of size n, the pseudocode is: 1. Initialize a set of counters of size range(n). Call this numCounters[], and set all elements to 0. 2. For each element i of the input array, increase numCounters(array[i]] by 1. Notice the index into the counter array is the value of the array element. For example, if the number happens to be '12', the counter with index 12 is incremented by 1 for that step. After completing the count, to rebuild the array into sorted order: 1. Set two counters i = 0 and j = 0. 2. For each index i in numCounters[], if numCounters[i] is nonzero, set the original array values array[j] to array[j + numCounters[i]] to the value of i. 3. Increment j by numCounters[i]. Assignment and sorts them with To complete this lab, write a program that reads numbers from this input file counting sort. Here are the other requirements: > 1. Verify that the array is sorted in ascending order using the same way as in previous labs (verifying a[i + 1] a[i] for all i). 2. You can assume that your input falls in the range 0-99 inclusive. 3. Output the array before and after the sorting. This should be freestanding code (we are not re-using the SortableBag class from last week). Example Output Array before sorting: 20 16 76 26 33 4 16 19 8 64 76 80 28 28 98 2 3 19 48 27 Array after sorting: 2 3 4 8 16 16 19 19 20 26 27 28 28 33 48 64 76 76 80 98Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started