zoukankan      html  css  js  c++  java
  • vector rIterator

    #include<vector>
    #include<iostream>
    using namespace std;
    
    void main()
    {
        vector<int> vInt;
        vInt.push_back(1);
        vInt.push_back(2);
        vInt.push_back(3);
        vInt.push_back(4);
        vInt.push_back(5);
    
        vector<int>::iterator it=vInt.begin();
        for (;it!=vInt.end();it++)
        {
            cout<<*it<<" ";
        }
        cout<<endl;
    
        vector<int>::reverse_iterator rit=vInt.rbegin();
        for (;rit!=vInt.rend();rit++)
        {
            cout<<*rit<<" ";
        }
        cout<<endl;
        
        it=vInt.end();
        for (--it;it!=vInt.begin();--it)
        {
            cout<<*it<<" ";
        }
        cout<<*it<<" ";
        cout<<endl;    
        
        if (*(vInt.rbegin())==*(vInt.end()-1))
        {
            cout<<"rbegin()== end()-1"<<endl;
        } 
        else
        {
            cout<<"rbegin()!=end()"<<endl;
        }
        if (*(vInt.rend()-1)==*(vInt.begin()))
        {
            cout<<"rend()-1 ==begin()"<<endl;
        } 
        else
        {
            cout<<"rend()!=begin()"<<endl;
        }
    
    }
    
    // 1 2 3 4 5
    // 5 4 3 2 1
    // 5 4 3 2 1
    // rbegin()== end()-1
    // rend()-1 ==begin()
    // Press any key to continue
  • 相关阅读:
    第一周作业
    第0次作业
    第三次作业
    第二次作业
    第一次作业
    第零次作业
    第三周作业
    第二周作业
    第一周作业
    关于如何学习计算机
  • 原文地址:https://www.cnblogs.com/sky20080101/p/6399794.html
Copyright © 2011-2022 走看看