C++标准库算法从小到大排序,sort( s.begin(),s.end(),isShorter )为什么没有向isShorter函数传递参数
将字符串按照长短从小到大排序程序代码:
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; }
C++标准库算法从小到大排序,sort( s.begin(),s.end(),isShorter )为什么没有向isShorter函数传递参数。