min_element(b , e)
min_element(b , e, op)
max_element(b , e)
max_element(b , e, op)
//
op 是函數,函數對象,一元謂詞
#include#include // #include bool absLess(int elem1, int elem2) { return abs(elem1) < abs(elem2); } using namespace std; int main() { deque ideq; ideq.insert(ideq.end(), -12); for (int i = 2; i <= 8; i++) { ideq.insert(ideq.end(), i); } for (int i = -3; i <= 5; i++) { ideq.insert(ideq.end(), i); } for (deque ::iterator iter = ideq.begin(); iter != ideq.end(); iter++) { cout << *iter << ' '; } cout << endl; deque ::iterator result = min_element(ideq.begin(), ideq.end()); cout << "最小值:" << *result << endl; cout << "最大值:" << *max_element(ideq.begin(), ideq.end()) << endl; cout << "絕對值最小值:" << *min_element(ideq.begin(), ideq.end(), absLess) << endl; cout << "絕對值最大值:" << *max_element(ideq.begin(), ideq.end(), absLess) << endl; // system("pause"); return 0; }