#include <iostream>
#include <set>
using namespace std;
void print( set< int > & s)
{
cout << "\n s = {" ;
auto p = s.begin ( ) ;
while ( p ! = s.end ( ) )
cout << * p++ << ",}" [ p== s.end ( ) ] ;
}
void print( multiset< int > & s)
{
cout << "\n ms = {" ;
auto p = s.begin ( ) ;
while ( p ! = s.end ( ) )
cout << * p++ << ",}" [ p== s.end ( ) ] ;
}
int main( )
{
int a[ ] = { 7 , 4 , 9 , 1 , 1 , 4 , 8 } ;
set< int > s( a, a + 7 ) ;
print( s) ;
s.insert ( 3 ) ;
print( s) ;
s.erase ( 3 ) ;
print( s) ;
set< int > :: iterator ix = s.find ( 4 ) ;
s.erase ( ix) ;
print( s) ;
s.erase ( s.find ( 7 ) , s.find ( 9 ) ) ;
print( s) ;
cout << "\n Count of 1: " << s.count ( 1 ) ;
cout << "\n Count of 2: " << s.count ( 2 ) ;
s.insert ( 2 ) ;
s.insert ( 4 ) ;
s.insert ( 5 ) ;
s.insert ( 7 ) ;
print( s) ;
auto it = s.lower_bound ( 5 ) ;
cout << "\n The lower bound of 5 is " << * it << "." ;
it = s.lower_bound ( 6 ) ;
cout << "\n The lower bound of 6 is " << * it << "." ;
it = s.lower_bound ( 10 ) ;
if ( it == s.end ( ) ) cout << "\n The lower bound of 10 is at the end of the range." ;
it = s.upper_bound ( 5 ) ;
cout << "\n The upper bound of 5 is " << * it << "." ;
it = s.upper_bound ( 6 ) ;
cout << "\n The upper bound of 6 is " << * it << "." ;
it = s.upper_bound ( 10 ) ;
if ( it == s.end ( ) ) cout << "\n The upper bound of 10 is at the end of the range." ;
auto it_pair = s.equal_range ( 5 ) ;
cout << "\n The bounds of 5 are " << * it_pair.first << " and " << * it_pair.second << "." ;
int b[ ] = { 1 , 1 , 2 , 3 , 4 , 4 , 4 , 5 } ;
multiset< int > ms( b, b+ 8 ) ;
print( ms) ;
auto p = ms.lower_bound ( 4 ) ;
cout << "\n " ;
while ( p ! = ms.upper_bound ( 4 ) )
cout << * p++ << " " ;
}
I2luY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JvdW5kKDQpKQogICAgICAgIGNvdXQgPDwgKnArKyA8PCAiICI7Cn0=
stdout
s = {1,4,7,8,9}
s = {1,3,4,7,8,9}
s = {1,4,7,8,9}
s = {1,7,8,9}
s = {1,9}
Count of 1: 1
Count of 2: 0
s = {1,2,4,5,7,9}
The lower bound of 5 is 5.
The lower bound of 6 is 7.
The lower bound of 10 is at the end of the range.
The upper bound of 5 is 7.
The upper bound of 6 is 7.
The upper bound of 10 is at the end of the range.
The bounds of 5 are 5 and 7.
ms = {1,1,2,3,4,4,4,5}
4 4 4