Get equal range with equal_range : equal_range « STL Algorithms Binary search « C++

Home
C++
1.Bitset
2.Class
3.Console
4.Data Structure
5.Data Type
6.Deque
7.Development
8.File
9.Function
10.Generic
11.Language
12.List
13.Map Multimap
14.Overload
15.Pointer
16.Qt
17.Queue Stack
18.Set Multiset
19.STL Algorithms Binary search
20.STL Algorithms Heap
21.STL Algorithms Helper
22.STL Algorithms Iterator
23.STL Algorithms Merge
24.STL Algorithms Min Max
25.STL Algorithms Modifying sequence operations
26.STL Algorithms Non modifying sequence operations
27.STL Algorithms Sorting
28.STL Basics
29.String
30.Valarray
31.Vector
C / ANSI-C
C Tutorial
C++ Tutorial
Visual C++ .NET
C++ » STL Algorithms Binary search » equal_rangeScreenshots 
Get equal range with equal_range
  
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

template <class T>
void print(T& c){
   fortypename T::iterator i = c.begin(); i != c.end(); i++ ){
      std::cout << *i << endl;
   }
}
int main( ){
    const int len = 15;
    const int a[len923375774105674};

    vector<int> va, a + len );
    vector<int>::iterator v_end = v.end();
    
    sortv.begin(), v.end() );
    
    vector<int>::iterator start = v.begin();
    int mode_range = 0;
    int mode_grade = 0;
    pair<vector<int>::iterator,vector<int>::iterator> range;
    
    // look for the largest range, which is the mode
    whilestart != v_end )
    {
        range = equal_rangestart, v_end, *start );
        ifrange.second - range.first > mode_range ){
           mode_range = range.second - range.first;
           mode_grade = *start;
        }
        start = range.second;
    }
    cout   << "Mode by method 2: " << mode_grade
           << "\n\nMinimum: " << v[0]
           << "  Maximum: " << v[len-1]
           << "  Median: " << v[len/2<< endl;
}
  
    
  
Related examples in the same category
1.Use equal_range to determine both the lower- and upper-bound insertion points
2.equal_range and distance
3.Use equal function to check whether both collections are equal
4.Use equal function to check for corresponding even and odd elements
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.