Mega Code Archive

 
Categories / C++ / Data Structure
 

Demonstrate count_if and not1 in vector

#include <iostream> #include <vector> #include <functional> #include <algorithm> using namespace std; int main() {   vector<char> vectorObject;   int num;   int i;   for(i = 0; i <26; i++)       vectorObject.push_back(i+'A');   cout << "Sequence contains:";   for(i = 0; i <vectorObject.size(); i++)     cout << vectorObject[ i ] << " ";   cout << endl;   num = count_if(vectorObject.begin(), vectorObject.end(), bind2nd(greater<int>(), 'r'));   cout << "There are " << num;   cout << " elements greater than E.\n";   num = count_if(vectorObject.begin(), vectorObject.end(), not1(bind2nd(greater<int>(), 'r')));   cout << "There are " << num;   cout << " elements not greater than E.";   return 0; }