C++ Lambda Expressions Sorting Data

Description

C++ Lambda Expressions Sorting Data

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

using namespace std;

void StandardSort(vector<int>& vect)
{
    sort(vect.begin(), vect.end());/*from   w  w w  .  j  ava  2 s . c om*/
    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