leproza

Find miminum even element

Apr 8th, 2022
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. template<typename T>
  4. bool execute( T* pBegin, T* pEnd, T* out )
  5. {
  6.     T* pCur = pBegin;
  7.     bool bFind = false;
  8.     while( pCur != pEnd )
  9.     {
  10.         if( (*pCur & 1) )
  11.         {
  12.             if( !bFind )  *out = *pCur;
  13.             else if( *out > *pCur ) *out = *pCur;
  14.             bFind = true;
  15.         }
  16.         pCur++;
  17.     }
  18.     return bFind;
  19. }
  20.  
  21. using namespace std;
  22.  
  23. int main()
  24. {
  25.     int A[] = { 10,4,32,2,10 };
  26.     int min = 0;
  27.     bool b = execute<int>( &A[0], &A[5], &min );
  28.     if( b ) cout << "Min value is " << min << endl;
  29.     else cout << "No such elements\n";
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment