Determine the upper and lower bound of value in multiset - C++ STL

C++ examples for STL:multiset

Description

Determine the upper and lower bound of value in multiset

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() // w w  w .j a  v  a2  s.  co  m
{ 
   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 
   
   // determine lower and upper bound of 22 in intMultiset 
   cout << "\n\nLower bound of 22: " << *( intMultiset.lower_bound( 22 ) ); 
   cout << "\nUpper bound of 22: " << *( intMultiset.upper_bound( 22 ) ); 


}

Result


Related Tutorials