
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Multiset Lower Bound in C++ STL with Examples
In this tutorial, we will be discussing a program to understand multiset lower_bound() in C++ STL.
The function lower_bound() returns the first existence of the element in the container equivalent to the provided parameter, else it returns the element immediately bigger than that.
Example
#include <bits/stdc++.h> using namespace std; int main(){ multiset<int> s; s.insert(1); s.insert(2); s.insert(2); s.insert(1); s.insert(4); cout << "The multiset elements are: "; for (auto it = s.begin(); it != s.end(); it++) cout << *it << " "; auto it = s.lower_bound(2); cout << "\nThe lower bound of key 2 is "; cout << (*it) << endl; it = s.lower_bound(3); cout << "The lower bound of key 3 is "; cout << (*it) << endl; it = s.lower_bound(7); cout << "The lower bound of key 7 is "; cout << (*it) << endl; return 0; }
Output
The multiset elements are: 1 1 2 2 4 The lower bound of key 2 is 2 The lower bound of key 3 is 4 The lower bound of key 7 is 5
Advertisements