#include <algorithm>
#include <numeric>
#include<functional>
#include <iostream>
#include<vector>
#include<string>
using namespace std;
template <class T>
struct display
{
void operator()(const T& x) const
{
cout << x << " ";
}
};
void showVector(vector<int> iv , string str )
{
cout << str ;
for (auto x : iv)
cout << x << " ";
cout << endl;
}
int transformfun(int i )
{
return i += 100;
}
int main()
{
int ia[9] = { 0,1,2,3,4,5,6,7,8 };
vector<int> iv1(ia, ia + 5);
vector<int> iv2(ia, ia + 9);
showVector(iv1, "This is iv1: ");
showVector(iv2, "This is iv2: ");
vector<int>::iterator it;
it = find(iv1.begin(), iv1.end(), 6);
if (it == iv1.end())
cout << " I can't find the number \n";
else
cout << " I find the number "<< *it << endl;
it = find(iv2.begin(), iv2.end(), 6);
if (it == iv2.end())
cout << " I can't find the number \n";
else
cout << " I find the number " << *it << endl;
it = find_first_of(iv1.begin(), iv1.end(), iv2.begin(), iv2.end());
if (it == iv1.end())
cout << " I can't find the number \n";
else
cout << " I find the number " << *it << endl;
it = find_end(iv1.begin(), iv1.end(), iv2.begin(), iv2.end());
if (it == iv1.end())
cout << " I can't find the number \n";
else
cout << " I find the number " << *it << endl;
it = search(iv2.begin(), iv2.end(), iv1.begin(), iv1.end());
if (it == iv2.end())
cout << " I can't find the number \n";
else
cout << " I find the string " << *it << endl;
int n = count(iv1.begin(), iv1.end(), 3);
cout << "the number 3 has " << n << " in the vector" << endl;
vector<int> iv3 = {99,88,77,66,55,44,33,22 };
showVector(iv3, "before copy iv3 : \t");
copy(iv1.begin(), iv1.end(), iv3.begin());
showVector(iv3, "after copy iv3 : \t");
transform(iv1.begin(), iv1.end(), iv3.begin(), transformfun);
showVector(iv3, "after transform iv3 : \t");
iv3.push_back(100);
replace(iv3.begin(), iv3.end(), 100, 111);
showVector(iv3, "after replace iv3 : \t");
fill(iv3.begin(), iv3.end(), 22);
showVector(iv3, "after fill iv3 : \t");
fill_n(iv3.begin(), 2, 11);
showVector(iv3, "after fill_n iv3 : \t");
iv3.push_back(1);
iv3.push_back(2);
sort(iv3.begin(),iv3.end());
showVector(iv3, "after sort iv3 : \t");
iv3.push_back(1);
iv3.push_back(2);
stable_sort(iv3.begin(), iv3.end());
showVector(iv3, "after stable_sort iv3 : \t");
iv3.push_back(8);
iv3.push_back(9);
partial_sort(iv3.begin() + 2, iv3.begin() + 6, iv3.end());
showVector(iv3, "after partial_sort iv3 : \t");
random_shuffle(iv3.begin(), iv3.end());
showVector(iv3, "after random_shuffle iv3 : \t");
reverse(iv3.begin(), iv3.end());
showVector(iv3, "after reverse iv3 : \t");
rotate(iv3.begin(), iv3.begin()+5, iv3.end());
showVector(iv3, "after rotate iv3 : \t");
merge(iv1.begin(), iv1.begin(), iv2.begin(), iv2.end(),iv3.begin());
showVector(iv3, "after rotate iv3 : \t");
cout << equal(iv1.begin(), iv1.end(), iv2.begin(), iv2.end())<<endl;
cout<<includes(iv2.begin(), iv2.end(), iv1.begin(), iv1.end()) << endl;
cout <<* max_element(iv2.begin(), iv2.end()) << endl;
cout <<* min_element(iv2.begin(), iv2.end()) << endl;
random_shuffle(iv2.begin(), iv2.end());
showVector(iv2, "after random_shuffle iv2 : \t");
make_heap(iv2.begin(), iv2.end());
showVector(iv2, "after make_heap iv2 : \t");
pop_heap(iv2.begin(), iv2.end());
showVector(iv2, "after pop_heap iv2 : \t");
push_heap(iv2.begin(), iv2.end());
showVector(iv2, "after push_heap iv2 : \t");
iv2.push_back(9);
showVector(iv2, "after iv2.push_back(9) iv2 : \t");
push_heap(iv2.begin(), iv2.end());
showVector(iv2, "after push_heap2 iv2 : \t");
sort_heap(iv2.begin(), iv2.end());
showVector(iv2, "after sort_heap iv2 : \t");
pair<vector<int>::iterator, vector<int>::iterator> p = mismatch(iv1.begin(), iv1.end(), iv2.begin());
if (p.first == iv1.end())
cout << "iv1.end" << endl;
else
cout << *(p.first) << endl;
if (p.second == iv2.end())
cout << "iv2.end" << endl;
else
cout << *(p.second) << endl;
cout << equal(iv1.begin(), iv1.end(), iv2.begin()) << endl;
}
