Advertisement
LEGEND2004

Iterators

Jul 27th, 2023
1,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. signed main()
  5. {
  6.     vector<int> v = {5 , 6 , 7 , 8};
  7.  
  8.     cout << *v.begin() << endl; // 5
  9.     cout << *v.end() << endl; //random number
  10.     cout << *(--v.end()) << endl; //8
  11.     cout << *(v.end()--) << endl; // random number
  12.     cout << *(v.begin()++) << endl; // 5
  13.     cout << *(++v.begin()) << endl; // 6
  14.     cout << *(v.begin() + 2) << endl; // number in 2-nd index
  15.     sort(v.begin() , v.end());
  16.     cout << *(lower_bound(v.begin() , v.end() , 7)) << endl; // 7
  17.     cout << *(upper_bound(v.begin() , v.end() , 7)) << endl; // 8
  18.     cout << *(upper_bound(v.begin() , v.end() , 8)) << endl; // random number
  19.  
  20.     auto it = v.begin();
  21.     cout << *it << endl; // 5
  22.     vector<int>::iterator pt = v.end();
  23.     pt--;
  24.     cout << *pt << endl; // 8
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement