Mega Code Archive

 
Categories / C++ Tutorial / Vector
 

Random access of a vector

#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(1500);     scores.push_back(3500);     scores.push_back(7500);     srand(time(0));     random_shuffle(scores.begin(), scores.end());     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; }