I have a small array with 7 elements which can have values from 0 to around 6 (very small numbers). The counting sort is really very efficient with such configuration, but, I have another array to keep track of indexes of the first array. For example:
main array: (initial) {0,3,5,1,0,2,4} secondary array (initial) {0,1,2,3,4,5,6}
main array: (sorted) {5,4,3,2,1,0,0}
secondary array (sorted) {2,6,1,5,3,4,0}
The first array should be sorted the regular way, while the second array’s indexes should correspond to their respected elements in the first array in the end.
How to sort arrays following these rules using countingsort and not bubblesort?
I have a working implementation using bubblesort, but I expect counting sort to work faster with the following set.
{element, original index}and sort that wrt the element.