## 24.4.3 Searching Algorithms - `max_element` and `min_element`

###

- Generalize `max` and `min` to collections

  > `vector<int> d(10);
  > // Generate ten random numbers
  > generate(d.begin(), d.end(), rand);
  > // Find largest value
  > vector<int>::iterator mx =
  > max_element(d.begin(), d.end());
  > // Find smallest value
  > vector<int>::iterator mn =
  > min_element(d.begin(), d.end());
  > if (mx != d.end()) // Will fail for empty vector
  > cout << "Largest is " << *mx
  > << " and smallest is " << *mn << "\n";`

prev |top |next