Sort elements in a vector with sort(scores.begin(), scores.end()); : vector sort « Vector « C++






Sort elements in a vector with sort(scores.begin(), scores.end());

  
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cstdlib>

using namespace std;

int main()
{
    vector<int>::const_iterator iter;

    vector<int> scores;
    scores.push_back(1);
    scores.push_back(3);
    scores.push_back(5);

    for (iter = scores.begin(); iter != scores.end(); ++iter)
        cout << *iter << endl;

    sort(scores.begin(), scores.end());
    for (iter = scores.begin(); iter != scores.end(); ++iter)
        cout << *iter << endl;

 return 0;
}
  
    
  








Related examples in the same category

1.Loop through a vector in a reversed order
2.Create const_reverse_iterator out of vector of pairs
3.Create const_iterator out of vector of pairs
4.sort a vector with duplicates