#include #include #include #include using namespace std;template void print(T& c){ for( typename T::iterator i = c.begin(); i != c.end(); i++ ){ std::cout << *i << endl; }}inlinebool second_less( const pair a, const pair b ){ return a.second < b.second; }int main( ){ const int len = 15; const int a[len] = { 9, 2, 3, 3, 7, 5, 7, 7, 4, 10, 5, 6, 7, 4, 7 }; vector v( a, a + len ); vector::iterator v_end = v.end(); print( v ); map frequency; for( vector::iterator i = v.begin(); i != v_end;++i ) ++frequency[*i]; pair mode_pair = *max_element( frequency.begin(),frequency.end(), second_less ); cout << "Mode by method 1: " << mode_pair.first; }