@kizhvac kampazitr
Could you state precisely your problem (I'll assume it's an assignment) - especially where it says you need to use Counting Sort.
If you need to count letters of each type then you would increment an integer array, not a string; say:
1 2 3
|
int buckets[26] = { 0 }; // you say latin letters, although from your name it might not be your alphabet;
// .....
++buckets[s[i] - 'a'];
|
You could go on to complete the sorting of s, although it would be, e.g.,
s.push_back((char)('a'+i));
Equally, however, you could go straight on to try to construct the palindrome directly from your buckets[] array instead of the sorted string. For even counts in a bucket, assemble half this number of characters from the front and half from the back of the palindrome. For odd counts (and there may be at most one, and then only for an odd-length string) put this character in the middle of the palindrome.
The key thing, however, is that if you intend to do any counting, then buckets[] needs to be an integer array; (or a map, but that's probably making things unnecessarily difficult).