當前位置:成語大全網 - 新華字典 - sort()函數對字符串字典序的排序問題

sort()函數對字符串字典序的排序問題

struct?node?{

char?str[20];

friend?bool?operator?<?(node?a,?node?b)?{

return?strcmp(a.str,?b.str)?<?0;

}

}?s[55];

int?main()?{

int?n;

while?(scanf("%d",?&n)?&&?n)?{

for?(int?i?=?0;?i?<?n;?++i)?scanf("?%s",?s[i].str);

sort(s,?s?+?n);

for?(int?i?=?0;?i?<?n;?++i)?printf("%s\n",?s[i].str);

}

return?0;

}