C, 121
I present a 128-char C solution without usingThis is quite long compared to other entries, but it does not rely on any built-in sorting andor ToLower functions:
i,j;main(k){char s[99];gets(s);for(;i<strlen(s);){j=i-1;k=s[i++];while(j>=0&&(s[j]|32)>(k|32))s[j+1]=s[j--];s[j+1]=k;}puts(s);}
j;main(k){char s[99],*p=s;gets(s);while(*p){j=p-s-1;k=*p++;while(j>=0&&(s[j]|32)>(k|32))s[j+1]=s[j--];s[j+1]=k;}puts(s);}
More readable version:
i,j; main(k) {
char s[99];
gets(s);
for(;i<strlen(s);) {
j=i-1;
k=s[i++];
while( j>=0 && (s[j]|32)>(k|32) )
s[j+1]=s[j--];
s[j+1]=k;
}
puts(s);
}
j; main(k) {
char s[99], *p=s;
gets(s);
while(*p) {
j = p-s-1;
k = *p++;
while(j >= 0 && (s[j]|32) > (k|32))
s[j+1] = s[j--];
s[j+1] = k;
}
puts(s);
}
This is an implementation of insertion sort with a case-insensitive comparison between elements (using the |32
bitwise operation). This is because in ASCII encoding uppercase letters and lowercase letters only differ by the 25 bit.