fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template <typename T>
  5. T my_max(const T &begin, const T &end) {
  6. T result = begin, it = begin;
  7. while (++it, it != end) {
  8. if (*it > *result) {
  9. result = it;
  10. }
  11. }
  12. return result;
  13. }
  14.  
  15. int main() {
  16. int array[] = {1,3,5,1,2,7,6,5};
  17. std::cout << *my_max(&array[0], &array[9]) << std::endl;
  18. std::vector<int> vector;
  19. vector.push_back(0);
  20. vector.push_back(3);
  21. vector.push_back(8);
  22. vector.push_back(2);
  23. vector.push_back(1);
  24. vector.push_back(6);
  25. std::cout << *my_max(vector.begin(), vector.end()) << std::endl;
  26. return 0;
  27. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
7
8