96
C++ Algorithm Function count()
C++ Algorithm count()function accepts ‘val’ as argument and compares for the occurrence of element ‘val’ in the range. The number of occurrence of that element is returned.
Syntax
Parameter
first: It is an input iterator to the first element in the range.
last: It is an input iterator to the last element in the range.
val: It is the element whose occurrence is being searched in the range.
Return value
The function returns the number of occurrence of the element ‘val’ in the range [first,last).
Example 1
Output:
50 appear 3 times. 70 appear 2 times.
Example 2
Output:
The number of times 6 appear is: 4
Complexity
The complexity of the function is linear up to a distance between first and last element.
Data races
Some or all of the elements of the range are accessed
Exceptions
The function throws an exception if any of the argument throws one.
Next TopicC++ Algorithm count_if Function