题解 | #迭代器遍历容器#

迭代器遍历容器

https://www.nowcoder.com/practice/0f7ab22e60ee4574a9d9c81412b26595

#include <bits/stdc++.h>
using namespace std;

int main() {

    // write your code here......
    vector<int>::iterator it1;
    vector<int>::reverse_iterator it2;
    vector <int> v1(5);
    for (it1 = v1.begin(); it1 != v1.end();) {
        cin >> *it1;
        it1++;
    }

    for (it1 = v1.begin(); it1 != v1.end();) {
        cout << *it1 << " ";
        it1++;
    }
    cout << endl;
    for (it2 = v1.rbegin(); it2 != v1.rend(); it2++) {
        cout << *it2 << " ";

    }
    return 0;
}

全部评论

相关推荐

程序员小白条:你不是有一段实习了吗,现在找中大厂实习?过段时间要秋招了
我的简历长这样
点赞 评论 收藏
分享
机械打工仔:我来告诉你原因,是因为sobb有在线简历,有些HR为了快会直接先看在线简历,初步感觉不合适就不会找你要详细的了
投了多少份简历才上岸
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-03 18:13
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务