C++ multiset count()C++ Multiset count() function is used to return the number of elements found in the container. Since, the multiset container does not contain any duplicate element, this function actually returns 1 if the element with value val is present in the multiset container otherwise, it returns 0. SyntaxParameterval: Value to be searched in the multiset container. Return valueIt returns 1 if the element with value val is present in the multiset container or 0 otherwise. ComplexityLogarithmic in size. Iterator validityNo changes. Data RacesThe container is accessed. Concurrently accessing the elements of container is safe. Exception SafetyIf an exception is thrown, there are no changes in the multiset. Example 1Let's see the simple example to search the element with the given key value: Output: The key 30 is present The key 100 is not present In the above example, count() function checks for the given value. If the element is present in the multiset container, then it will display the message that element is present otherwise, not present. Example 2Let's see a simple example to search for the elements of the multiset: Output: a is an element of mymultiset. b is not an element of mymultiset. c is an element of mymultiset. d is not an element of mymultiset. e is not an element of mymultiset. f is an element of mymultiset. g is not an element of mymultiset. In the above example, count() function is used to search for the 'a' to 'h' elements in the multiset. Example 3Let's see a simple example to search keys in the multiset: Output: 'a' is present in the multiset 'z' is not present in the multiset In the above example, key 'a' is present in the multiset m hence, it will be the value of 'a' and key 'z' is not present in the multiset hence, there is no value of 'z'. Example 4Let's see a simple example: Output: The number of elements in s1 with a sort key of 1 is: 1. The number of elements in s1 with a sort key of 2 is: 0. Next TopicC++ multiset |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India