fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. vector<int> myvector;
  10. srand(666);
  11.  
  12. // set some values:
  13. for ( int i = 0; i < 10; i++ )
  14. myvector.push_back(rand());
  15.  
  16. // nth_element around the 4th element
  17. nth_element (myvector.begin(), myvector.begin()+4, myvector.end());
  18.  
  19. // print results
  20. for (vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
  21. cout << " " << *it;
  22.  
  23. cout << endl;
  24. }
Success #stdin #stdout 0.01s 2860KB
stdin
Standard input is empty
stdout
 775348041 190469822 93023211 887117265 922803881 1159008879 1163445918 1421975561 2057881578 1437972786