Potentially, but i think it should really go more like this:
1 2 3 4 5 6
for (int i = 0; i < numOfNames; i++) {
for (int j = 1; j <= numOfNames; j++) {
if (counter[j] < counter[j - 1])
swap(counter[j], counter[j - 1]);
}
}
This will sort an array of strings according to the total ascii value of each of the words. For example, the word 'dog' has a total ascii value of 100+111+103 (see http://ee.hawaii.edu/~tep/EE160/Book/chap4/subsection2.1.1.1.html for character values). If you want to sort the words by their first letter, then you need compare the first letter of the word(s).