How to compare every element of the array?

Hello there C++ forum.
I am i need of your assistance.
I have to code an app where the user inputs values in 2 different arrays,and compare the values.If the value in array1 is greater or equal to the value of array2, then a counter increments , else it does nothing.That Procedure continues until every element of both arrays are compared with each other.I did the input and sorting part,but I do not know how to compare every element of an array.
Any help will be appreciated.
Thanks
~W0ot
Last edited on
You may use the following algorithm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
template <typename InputIterator1,
                typename InputIterator2,
                typename BinaryPredicate>

typename std::iterator_traits<InputIterator1>::difference_type 
count( InputIterator1 first1, InputIterator1 last1,
          InputIterator2 first2, BinaryPredicate binary_predicate )
{
   typename std::iterator_traits<InputIterator1>::difference_type n = 0;

   for ( ; first1 != last1 ; ++first1, ++first2 )
   {
      if ( binary_predicate( *first1, *first2 ) ) ++n;
   }

   return ( n );
}



For example,

int n = count( arrray1, array1 + size, arrray2, std::greater_equal<int>() );
Last edited on
Topic archived. No new replies allowed.