#include<ctype.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
int my_strcmp(const void* elem1,const void* elem2)
{
assert(elem1&&elem2);
char ret1 = *(char*)elem1;
char ret2 = *(char*)elem2;
if(isupper(*(char*)elem1))//大写变小写
{
ret1 = 'a'-'A'+*(char*)elem1;
}
if(isupper(*(char*)elem2))//大写变小写
{
ret2 = 'a'-'A'+*(char*)elem2;
}
return ret1 - ret2;
}
void my_swap(char* elem1,char* elem2,int width)
{
int i = 0;
for(i = 0;i<width;i++)
{
char temp = *(elem1+i);
*(elem1+i) = *(elem2+i);
*(elem2+i) = temp;
}
}
void my_bubblesort(void* arr,int len,int width,int(*p)(const void*,const void*))
{
assert(arr);
int i = 0,j = 0;
for(i=0;i<len-1;i++)
{
for(j = 0;j<len - i - 1;j++)
{
int flag = 0;
while (0 == isalpha(*((char*)arr + j)))//如果当前位置的不是字母
{
j++;
if ('\0' == *((char*)arr + j))
{
break;
}
}
int ret = j+1;
while(0 == isalpha(*((char*)arr+ret)))//如果下一个位置不是字母,再往下找,直到是字母为止
{
ret++;
if('\0' == *((char*)arr+ret))
{
flag = 1;
break;
}
}
if(1 == flag)
{
break;
}
if((*p)((char*)arr+j*width,(char*)arr+ret*width)>0)
{
my_swap((char*)arr+j*width,(char*)arr+ret*width,width);
}
}
}
}
int main()
{
char* arr = (char*)calloc(2000,sizeof(char));
if(NULL == arr)
{
perror("calloc");
return 0;
}
gets(arr);
my_bubblesort(arr,strlen(arr),sizeof(char),my_strcmp);
printf("%s",arr);
int i = 0;
return 0;
}