fork download
  1. #include <iostream> // std::cout
  2. #include <algorithm> // std::sort
  3. #include <vector> // std::vector
  4.  
  5. bool myfunction (int i,int j) { return (i<j); }
  6.  
  7. int main () {
  8. int myints[] = {32,71,12,45,26,80,53,33};
  9. std::vector<int> myvector (myints, myints+8);
  10.  
  11. // using function as comp
  12. std::sort (myvector.begin()+4, myvector.end(), myfunction);
  13.  
  14. // print out content:
  15. std::cout << "myvector contains:";
  16. for (std::vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
  17. std::cout << ' ' << *it;
  18. std::cout << '\n';
  19.  
  20. return 0;
  21. }
Success #stdin #stdout 0s 4192KB
stdin
Standard input is empty
stdout
myvector contains: 32 71 12 45 26 33 53 80