Using equal_range to determine lower and upper bound of an element in intMultiset - C++ STL

C++ examples for STL:multiset

Description

Using equal_range to determine lower and upper bound of an element in intMultiset

Demo Code

#include <iostream> 
 #include <set> // multiset class-template definition 
 #include <algorithm> // copy algorithm 
 #include <iterator> // ostream_iterator 
using namespace std; 

// define short name for multiset type used in this program 
typedef multiset< int, less< int > > Ims; 

int main() //from   ww  w  . jav a2s  .c  om
{ 
   const int SIZE = 10; 
   int a[ SIZE ] = { 7, 22, 9, 1, 18, 30, 100, 22, 85, 13 }; 
   Ims intMultiset; // Ims is typedef for "integer multiset" 
   ostream_iterator< int > output( cout, " " ); 

   intMultiset.insert( 35 ); // insert 5 in intMultiset 
   intMultiset.insert( 15 ); // insert 15 in intMultiset 
   intMultiset.insert( 5 ); // insert 5 in intMultiset 
   intMultiset.insert( 1 ); // insert 5 in intMultiset 
   // p represents pair of const_iterators 
   pair< Ims::const_iterator, Ims::const_iterator > p; 

   // use equal_range to determine lower and upper bound 
   // of 22 in intMultiset 
   p = intMultiset.equal_range( 22 ); 

    cout << "\n\nequal_range of 22:" << "\n               Lower bound: " 
        << *( p.first ) << "\n          Upper bound: " << *( p.second ); 
    cout << endl; 
}

Result


Related Tutorials