![]() |
#2
rjsp2016-11-04 10:34
|

bool isShorter( const string &s1, const string &s2 )
{
return s1.size( ) < s2.size( ) ;
}
int main( )
{
vector<string> sVec{ "the","quick","red","fox","jumps","over","the","slow","red","turtle" };
sort(sVec.begin(), sVec.end(), isShorter );
for (vector<string>::iterator i = sVec.begin(); i != sVec.end(); ++i) {
cout << *i << " ";
}cout << endl;
return 0;
}
{
return s1.size( ) < s2.size( ) ;
}
int main( )
{
vector<string> sVec{ "the","quick","red","fox","jumps","over","the","slow","red","turtle" };
sort(sVec.begin(), sVec.end(), isShorter );
for (vector<string>::iterator i = sVec.begin(); i != sVec.end(); ++i) {
cout << *i << " ";
}cout << endl;
return 0;
}
C++标准库算法从小到大排序,sort( s.begin(),s.end(),isShorter )为什么没有向isShorter函数传递参数。