sort中第三个参数是个函数指针,返回类型bool,接受两个元素对象。
我想知道其完整的定义类型
bool (*pred) (****,****);
don't know if i understand what you need.
The predicate (I don't know if it should be translated as "weici") can be a funtion pointer and function object --- a class which overloads operator().
Here is what I copied from cplusplus.com
// sort algorithm example
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;bool myfunction (int i,int j) { return (i<j); }
struct myclass {
bool operator() (int i,int j) { return (i<j);}
} myobject;int main () {
int myints[] = {32,71,12,45,26,80,53,33};
vector<int> myvector (myints, myints+8); // 32 71 12 45 26 80 53 33
vector<int>::iterator it;// using default comparison (operator <):
sort (myvector.begin(), myvector.begin()+4); //(12 32 45 71)26 80 53 33// using function as comp
sort (myvector.begin()+4, myvector.end(), myfunction); // 12 32 45 71(26 33 53 80)// using object as comp
sort (myvector.begin(), myvector.end(), myobject); //(12 26 32 33 45 53 71 80)// print out content:
cout << \"myvector contains:\";
for (it=myvector.begin(); it!=myvector.end(); ++it)
cout << \" \" << *it;cout << endl;
return 0;
}