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

迭代器遍历容器

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

#include <iostream>
// write your code here......
#include <vector>
using namespace std;

int main() {

    vector<int> v;
    int a = 5, i =0;
    v.resize(a);
    while(a--)
        cin >> v[i++];
    vector<int>::iterator it = v.begin();
    while(it != v.end())
    {
        cout << *it << " ";
        it++;
    }
    cout <<endl;
    vector<int>::reverse_iterator it1 = v.rbegin();
    while(it1 != v.rend())
    {
        cout << *it1 << " ";
        it1++;
    }
    cout << endl;

    return 0;
}

全部评论

相关推荐

07-15 18:09
门头沟学院 Java
点赞 评论 收藏
分享
仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
06-07 00:00
已编辑
腾讯_后端开发
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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