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