Last Updated : 10 Apr, 2024
multiset<int> mst;
mst.insert(20);
mst.insert(30);
mst.insert(10);
mst.insert(50);
mst.insert(10);
    
multiset<int> :: iterator itr;
for(itr = mst.begin(); itr != mst.end(); itr++)
  cout << *itr << \" \";
cout << endl;
cout << mst.count(10); 

Possible outcome for the above code snippet
(A) 10 20 30 50
1
(B) 50 30 20 10
1
(C) 10 10 20 30 50
2
(D) None of these


Answer: (C)

Explanation:
Multisets are a type of associative containers similar to set, with an exception that multiple elements can have same values.
count(val): Returns the number of matches to element ā€˜gā€™ in the multiset.


Share your thoughts in the comments