clear(): This function is available in the File: unordered_set.h
Syntax:
void std::unordered_set<int>::clear()
This function erases all elements in an unordered_set.
Note: This function only erases the elements and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
File: unordered_set.h
For Example:
st = {9,4}
st.erase()= > It erases all the elements.
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){unordered_set<int> st;st.insert(9);st.insert(4);st.clear();cout << st.size() << "\n";return 0;}
Output:
0
No comments:
Post a Comment