unordered_set empty() function in C++ STL
Last Updated :
16 Nov, 2023
The unordered_set::empty is a built-in function in C++ STL which is used to check if an unordered_set container is empty or not. It returns True if the unordered_set container is empty, otherwise it returns False.
Syntax:
set_name.empty()
Parameters: This function does not accepts any parameter.
Return Value: It returns a boolean value True if the unordered_set container is empty, else false.
Below programs illustrate the above function:
Program 1:
CPP
#include <iostream>
#include <unordered_set>
using namespace std;
int main()
{
unordered_set< int > sample;
if (sample.empty() == true )
cout << "true" << endl;
else
cout << "false" << endl;
sample.insert(5);
if (sample.empty() == true )
cout << "true" << endl;
else
cout << "false" << endl;
return 0;
}
|
Program 2:
CPP
#include <iostream>
#include <unordered_set>
using namespace std;
int main()
{
unordered_set< int > uset;
uset.insert({ 5, 6, 7, 8 });
if (uset.empty() == true )
cout << "true" << endl;
else
cout << "false" << endl;
return 0;
}
|
Time complexity: O(1)
Share your thoughts in the comments
Please Login to comment...