2 int countOccurrencesconst vector v int k Implement the fu

2) int countOccurrences(const vector & v, int k)

Implement the function countOccurrences whose declaration appears above. The first argument of the function is a vector v of integers and the second argument is an integer k. The function returns the number of times k occurs in v

Solution

template<typename T>
int countOccurrences(const vector<T> & v, int k)
{
   int count = 0;
   for (int i = 0; i < v.size(); i++)
   {
       if (v[i] == k)
           count++;
   }
   return count;
}

2) int countOccurrences(const vector & v, int k) Implement the function countOccurrences whose declaration appears above. The first argument of the function

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site