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

迭代器遍历容器

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-07 14:30
复旦大学 Java
遇到这种人我也不知道说啥了
无能的丈夫:但我觉得这个hr语气没什么问题啊(没有恶意
点赞 评论 收藏
分享
点赞 评论 收藏
分享
05-22 12:44
已编辑
门头沟学院 golang
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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