#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iterator>
using namespace std;

int main(){
    vector<int> a;
    a.push_back(3);
    a.push_back(0);
    a.push_back(2);
    a.push_back(1);
    //                      v--- a.end()  [one-pass-the-end]
    // a : [3 | 0 | 2 | 1 ]
    //      ^
    //    a.begin()
    
    sort(a.begin(), a.end());
    for (int i = 0; i < a.size(); ++i)
      cout << a[i] << ' ';
    cout << endl;
    
    copy(a.begin(), a.end(), ostream_iterator<int>(cout, " "));
    cout << endl;
    
    int b[] = { 9, 6, 7, 3, 10, 22 };
    int bsize = sizeof(b) / sizeof(b[0]);
    reverse(b, b + bsize);
    // stl algorithm also works with array (builtin type)
    // even they are not really iterator
    for (int i = 0; i < bsize; ++i)
       cout << b[i] << ' ';
       cout << endl;   
       
   vector<int>::iterator p = max_element(a.begin(), a.end());
   // iterator is an inner class of  vector<int> (0396 5 years ago)
   cout << *p << endl; 
   
   cout << *min_element(b, b + bsize) << endl;
   
       
}
    
    
    
