It would make sense to store the word and its count in an STL map ( ) using the word as the key and the count as the data.

Then you don't need a counting algorithm as such; when you want to add a word to the list, first check it exists, if it does you increase the count; if not just add it with a count of 1. Also you don't need a sorting algorithm as map handles this for you.

However if you're not allowed to use the STL then perhaps just store a struct of the string and its count in a static array (malloc), resizing it as necessary (realloc). Use insertion sort, i.e. just place a new word into its correct place and shift the remaining items up; this is likely to be quick enough on modern systems.