Advertisement
karbaev

stl-vector-sort

Mar 4th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. // sort algorithm example
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int main ()
  8. {
  9.     int myints[] = {32,71,12,45,26,80,53,33};
  10.     vector<int> myvector (myints, myints+8);
  11.     // теперь в контейнере: 32 71 12 45 26 80 53 33
  12.     vector<int>::iterator it;
  13.  
  14.     // сортируем первые 4 элемента
  15.     sort (myvector.begin(), myvector.begin()+4);
  16.     // теперь в контейнере: (12 32 45 71)26 80 53 33
  17.  
  18.     // печатаем содежимое
  19.     cout << "myvector contains:";
  20.     for (it=myvector.begin(); it!=myvector.end(); ++it)
  21.         cout << " " << *it;
  22.  
  23.     cout << endl;
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement