Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,994 questions

51,939 answers

573 users

How to get an equal range of an element of a set in C++

1 Answer

0 votes
// Returns the bounds of a range that includes all the elements in the container 
// that is equivalent to a value

#include <iostream>  
#include <set> 
 
using std::set;
using std::cout;
using std::endl;
 
void printList(const set<int>& flist)
{
    for (auto elem : flist) {
        cout << elem << ' ';
    }
    cout << endl;
}
 
int main()
{
    set<int> st = { 1, 2, 3, 5, 7, 9, 14 };
 
    printList(st);
 
    cout << "equal_range(3).first = " << *st.equal_range(3).first << 
            " equal_range(3).second = " << *st.equal_range(3).second << endl;
    cout << "equal_range(4).first = " << *st.equal_range(4).first << 
            " equal_range(4).second = " << *st.equal_range(4).second << endl;
    cout << "equal_range(5).first = " << *st.equal_range(5).first << 
            " equal_range(5).second = " << *st.equal_range(5).second << endl;
}
 
 
/*
run:
 
1 2 3 5 7 9 14 
equal_range(3).first = 3 equal_range(3).second = 5
equal_range(4).first = 5 equal_range(4).second = 5
equal_range(5).first = 5 equal_range(5).second = 7

 
*/

 



answered Jan 9, 2018 by avibootz
edited Dec 12, 2024 by avibootz

Related questions

2 answers 170 views
2 answers 112 views
112 views asked Oct 21, 2022 by avibootz
3 answers 111 views
111 views asked Oct 21, 2022 by avibootz
1 answer 92 views
...