题解 | #迭代器遍历容器#
迭代器遍历容器
http://www.nowcoder.com/practice/0f7ab22e60ee4574a9d9c81412b26595
#include <iostream>
// write your code here......
#include <algorithm>
#include <vector>
using namespace std;
void print(int i) {
cout << i << " ";
}
void print_reverse(int i) {
cout << i << " ";
}
int main() {
// write your code here......
vector<int> v;
int num = 0;
for (int i = 0; i < 5; i++) {
cin >> num;
v.push_back(num);
}
for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
cout << *it << " ";
}
cout << endl;
for (vector<int>::iterator it = v.end() - 1; it != v.begin() - 1; it--) {
cout << *it << " ";
}
return 0;
}