如果输入很长(>> 255),您可以进行计数排序。
char chars[256]; zeroed
while( *input) // zero termination
chars[*input++]++;
Run Code Online (Sandbox Code Playgroud)
并像这样提取它
int pos = 0;
for(int i = 'A'; i<= 'Z'; i++)
{
while( chars[i]-- )
output(pos++] = (char)i;
while( chars[i+'a'-'A']-- )
output(pos++] = (char)i+'a'-'A';
}
Run Code Online (Sandbox Code Playgroud)
在)