#include #include #include #include using namespace std; bool less_than_7(int x) { return x<7; } void print(int i) { cout << "Ecco il mio valore " << i << endl; } int main() { vector vint; vint.push_back(1); vint.push_back(3); cout << "vint " << vint.size() << endl; for (unsigned int i=0; i(cout,",")); cout << endl; sort(vint.begin(), vint.end()); cout << "sorted" << endl; copy(vint.begin(), vint.end(), ostream_iterator(cout,",")); cout << endl; cout << "Shuffled" << endl; random_shuffle(vint.begin(), vint.end()); copy(vint.begin(), vint.end(), ostream_iterator(cout,",")); cout << endl; // Count int n=count(vint.begin(), vint.end(), 5); cout << "Nun entries ==5 " << n << endl; // Count_if n=count_if(vint.begin(), vint.end(), less_than_7); cout << "Nun entries <7 " << n << endl; //replace_if replace_if(vint.begin(), vint.end(), less_than_7, 0); copy(vint.begin(), vint.end(), ostream_iterator(cout,",")); // copy cout << "First 5 numbers" << endl; vector vint5(vint.size()); copy(vint.begin(), vint.begin()+5, vint5.begin()); cout << "vint5 " << vint5.size() << endl; copy(vint5.begin(), vint5.end(), ostream_iterator(cout,",")); cout << endl; // copy cout << "First 10 numbers" << endl; vector vint10; copy(vint.begin(), vint.end(), back_inserter(vint10)); cout << "vint10 " << vint10.size() << endl; copy(vint10.begin(), vint10.end(), ostream_iterator(cout,",")); cout << endl; cout << "vint before unique" << vint.size() << endl; sort(vint.begin(), vint.end()); copy(vint.begin(), vint.end(), ostream_iterator(cout,",")); cout << endl; vector::iterator last = unique(vint.begin(), vint.end()); cout << "vint after unique " << vint.size() << endl; copy(vint.begin(), last , ostream_iterator(cout,",")); cout << endl; copy(vint.begin(), vint.end() , ostream_iterator(cout,",")); cout << endl; // for_each for_each(vint.begin(), vint.end(), print ); return 0; }