c 2b 2b iterate over vector backwards

Solutions on MaxInterview for c 2b 2b iterate over vector backwards by the best coders in the world

showing results for - "c 2b 2b iterate over vector backwards"
Till
15 Aug 2018
1#include <iostream>
2#include <vector>
3
4using namespace std;
5
6int main(void) {
7   vector<int> v = {1, 2, 3, 4, 5};
8
9   /* Iterate vector in reverse order */
10   for (auto it =  v.rbegin(); it != v.rend(); ++it)
11      cout << *it << endl;
12  
13   /* Iterate vector in reverse order */
14    for(int i = v.size() - 1; i >= 0; i--)
15        std::cout << v[i] << endl;
16
17   return 0;
18}