
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
C++ STL Multiset Empty Function
In this article we will be discussing the working, syntax and examples of multiset::empty() function in C++ STL.
What is a multiset in C++ STL?
Multisets are the containers similar to the set container, meaning they store the values in the form of keys same as a set, in a specific order.
In multiset the values are identified as keys as same as sets. The main difference between multiset and set is that the set has distinct keys, meaning no two keys are the same, in multiset there can be the same keys value.
Multiset keys are used to implement binary search trees.
What is multiset::empty()?
multiset::empty() function is an inbuilt function in C++ STL, which is defined in <set> header file.
This function checks if the associated multiset container is empty or not.
empty() checks the associated container size is 0 then will be true, else if any elements are present in the container or the size of the container is not 0 then the function will return false.
Syntax
ms_name.empty();
Parameters
The function accepts no parameter.
Return value
This function Boolean value true, if the container is empty else false.
Example
Input: std::multiset<int> mymultiset = {1, 2, 2, 3, 4}; mymultiset.empty(); Output: false Input: std::multiset<int> mymultiset; mymultiset.empty(); Output: true
Example
#include <bits/stdc++.h> using namespace std; int main() { int arr[] = {2, 3, 4, 5}; multiset<int> check(arr, arr + 4); if (check.empty()) cout <<"The multiset is empty"; else cout << "The multiset isn't empty"; return 0; }
Output
If we run the above code it will generate the following output −
The multiset isn't empty
Example
#include <bits/stdc++.h> using namespace std; int main() { int arr[] = {}; multiset<int> check(arr, arr + 0); if (check.empty()) cout <<"The multiset is empty"; else cout << "The multiset isn't empty"; return 0; }
Output
If we run the above code it will generate the following output −
The multiset is empty