I'm looking for an algorithm in C that sorts array elements by frequency (least to most frequent). For example:
array[10] = {1, 1, 1, 5, 2, 3, 3, 3, 3, 4}; //initial array
array[10] = {5, 4, 2, 1, 1, 1, 3, 3, 3, 3}; //post-sorting array
The order of the elements with similar frequencies (5, 4, and 2 in the example above) do not matter, so long as they are grouped with others of the same frequency.
I am not sure how to go about doing this, I saw THIS , however it is in matlab (which I don't know) rather than C, and it relies heavily on library functions, something I'm trying not to do.