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

迭代器遍历容器

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

#include <iostream>
#include <iterator>
#include <vector>
// write your code here......

using namespace std;

int main() {

    // write your code here......
    vector<int > vec;
    int a;
    while (cin >> a) {
        vec.push_back(a);
    }

    vector<int>::iterator iter = vec.begin();
    while (iter != vec.end()) {
        cout << *iter << " ";
        iter++;
    }

    cout << endl;
    while (iter != vec.begin()) {
        iter--;
        cout << *iter << " ";

    }

    return 0;
}

全部评论

相关推荐

10-30 19:23
已编辑
山东大学(威海) C++
牛至超人:其实简历是不需要事无巨细的写的,让对方知道你有这段经历就行了,最重要的是面试的时候讲细讲明白
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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