Sort the data into a custom order Using a predicate with sort - C++ STL Algorithm

C++ examples for STL Algorithm:sort

Description

Sort the data into a custom order Using a predicate with sort

Demo Code

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

using namespace std;

bool IsGreater(int left, int right)
{
    return left > right;
}

int main(int argc, char* argv[])
{
    vector<int> myVector{ 10, 6, 4, 7, 8, 3, 9 };
    sort(myVector.begin(), myVector.end(), IsGreater);

    for (auto&& element : myVector)
    {//from   w w w.j ava2s .com
        cout << element << ", ";
    }

    return 0;
}

Result


Related Tutorials