C++ sort() on vector

Description

C++ sort() on vector

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void StandardSort(vector<int>& vect)
{
    sort(vect.begin(), vect.end());//from ww w.ja  v a2  s  . c  o  m
    cout << "Using the Standard Sort" << endl;
    for_each(vect.begin(), vect.end(), [](int x){cout << x << endl;});
}

void ProcessVector(vector<int>& vect)
{
    sort(vect.begin(), vect.end(), [](int S1, int S2){return S1 > S2;});
    cout << "Using a Custom Sort" << endl;
    for_each(vect.begin(), vect.end(), [](int x){cout << x << endl;});
}

int main()
{
    vector<int> myV;
    myV.push_back(11);
    myV.push_back(2);
    myV.push_back(33);
    myV.push_back(4);

    StandardSort(myV);
    ProcessVector(myV);
}



PreviousNext

Related