char *countries[] =
{
"Nepal",
"Cambodia",
"Afghanistan",
"China",
"Singapore",
"Bangladesh",
"India",
"Maldives",
"South Korea",
"Bhutan",
"Japan",
"Sikkim",
"Sri Lanka",
"Burma",
"North Korea",
"Laos",
"Malaysia",
"Indonesia",
"Turkey",
"Mongolia",
"Pakistan",
"Philippines",
"Vietnam",
"Palestine"
};
void paiXuWithUsrBlock(char * countries[],int length,BOOL (^wusedashiBlock)(char * opXing1,char * opXing2))
{
char *temp = nil;
for (int i = 0; i < length - 1; i++) {
for (int j = 0; j < length - i -1; j++) {
if( wusedashiBlock(countries[j],countries[j+1]))
{
temp = countries[j];
countries[j] = countries[j+1];
countries[j+1] = temp;
}
}
}
for (int i = 0; i < length; i++) {
printf("%s\n",countries[i]);
}
}
int main()
{
BOOL (^wusedashiBlock)(char * opXing1,char * opXing2) = ^BOOL(char * opXing1,char * opXing2){
// BOOL result = ((int)strlen(opXing1)-(int)strlen(opXing2)<0);
BOOL result = (strcmp(opXing1, opXing2)>0);
return result;
};
paiXuWithUsrBlock(countries,24,wusedashiBlock);
return 0;
} |