Get the minimum element in a sequence with algorithm min_element - C++ STL Algorithm

C++ examples for STL Algorithm:min_element

Description

Get the minimum element in a sequence with algorithm min_element

Demo Code

#include <iostream> 
#include <algorithm> // algorithm definitions 
#include <numeric> // accumulate is defined here 
#include <vector> 
#include <iterator> 
using namespace std;

int main()/*from w w w  .j  av  a2 s. co  m*/
{
  const int SIZE = 10;
  int a1[SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  vector< int > v(a1, a1 + SIZE); // copy of a1 
  ostream_iterator< int > output(cout, " ");

  // locate minimum element in v2 
  cout << "\n\nMinimum element in Vector v2 is: "
    << *(min_element(v.begin(), v.end()));

}

Result


Related Tutorials