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

迭代器遍历容器

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

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

int main() {

    // write your code here......
    vector<int> v;
    
    for(int i=0;i<5;i++)
    {
        int temp=0;
        cin>>temp;
        v.push_back(temp);
        
    }
    //正向迭代器
    for(vector<int>::iterator it=v.begin();it!=v.end();it++)
    {
        cout<<*it<<" ";
    }
    cout<<endl;
    //反向迭代器
    for(vector<int>::reverse_iterator revit=v.rbegin();revit!=v.rend();revit++)
    {
        cout<<*revit<<" ";
    }

    return 0;
}
全部评论

相关推荐

驼瑞驰_招募评论官版...:反正我信了,上牛客,拿offer
腾讯开奖372人在聊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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