
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 Upper Bound in C++ STL with Examples
In this tutorial, we will be discussing a program to understand multiset upper_bound() in C++ STL.
The function upper_bound() returns the pointer to an element which is bigger than the one provided as a parameter, else it returns the pointer to the last element in the container.
Example
#include <bits/stdc++.h> using namespace std; int main(){ multiset<int> s; s.insert(1); s.insert(3); s.insert(3); s.insert(5); s.insert(4); cout << "The multiset elements are: "; for (auto it = s.begin(); it != s.end(); it++) cout << *it << " "; auto it = s.upper_bound(3); cout << "\nThe upper bound of key 3 is "; cout << (*it) << endl; it = s.upper_bound(2); cout << "The upper bound of key 2 is "; cout << (*it) << endl; it = s.upper_bound(10); cout << "The upper bound of key 10 is "; cout << (*it) << endl; return 0; }
Output
The multiset elements are: 1 3 3 4 5 The upper bound of key 3 is 4 The upper bound of key 2 is 3 The upper bound of key 10 is 5
Advertisements