Sorting a vector into descending order in vector
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
vector<char> vectorObject(26);
int i;
for(i = 0; i <vectorObject.size(); i++)
vectorObject[ i ] = 'A'+i;
cout << "Original ordering of vectorObject:";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[ i ] << " ";
cout << endl;
// sort into desceding order
sort(vectorObject.begin(), vectorObject.end(), greater<char>());
cout << "After sorting vectorObject using greater():";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[ i ] << " ";
return 0;
}
Related examples in the same category