Home > Java > javaTutorial > How to set up a sequential container

How to set up a sequential container

坏嘻嘻
Release: 2018-09-14 13:57:35
Original
1470 people have browsed it

This article mainly introduces how to set up sequential containers. I hope you will learn patiently.

#include<iostream>#include<string>#include<vector>#include<deque>#include<list>//各种顺序容器的常见操作
//vector  list dequeusing namespace std;int main()
{    vector<int> a;    const vector<int> ca;//常迭代器
    list<int> b;    deque<int> c;

    a.push_back(10);
    a.push_back(20);
    a.push_back(30);

    b.push_back(100);
    b.push_back(200);
    b.push_back(300);

    c.push_back(1);
    c.push_back(2);
    c.push_back(3);    for (vector<int>::size_type i = 0; i < a.size(); ++i)
    //int可能不够大,可能超过i的范围
    {        cout << a[i] << endl;
    }    ////list链表没有下标
    //for (list<int>::size_type k = 0; k < b.size(); ++k)
    //{
    //  cout << b[k] << endl;
    //}
    for (deque<int>::size_type n = 0; n < c.size(); ++n)
    {        cout << c[n] << endl;
    }    vector<int>::iterator first = a.begin(); 
    vector<int>::iterator last = a.end();    while (first != last)
    {        cout << "迭代器循环" << endl;        cout << *first << endl;
        ++first;
    }    vector<int>::const_iterator cfirsta = ca.begin();//const不能push_back 数据


    vector<int>::reverse_iterator rfirsta = a.rbegin();//逆序迭代器
    vector<int>::reverse_iterator rlastra = a.rend();//从最后一个倒着向前


    vector<int>::size_type              a1;    vector<int>::iterator    a2;//迭代器
    vector<int>::const_iterator         a3;//常迭代器
    vector<int>::reverse_iterator       a4;//逆序迭代器,从最后一个元素向前迭代
    vector<int>::const_reverse_iterator a5;//常逆序迭代器
    vector<int>::difference_type        a6;//容器中两个数据之间的距离
    vector<int>::value_type             a7;    //vector<int>::reference  a8;
    //引用,引用必须初始化
    //vector<int>::const_reference        a9;//常引用

    list<int>::size_type         
            b1;    list<int>::iterator       
              b2;    list<int>::const_iterator    
            b3;    list<int>::reverse_iterator   
            b4;    list<int>::const_reverse_iterator  
             b5;    list<int>::difference_type        
             b6;    /*list<int>::reference          
            b7;*/
    //如上,deque同上
    system("pause");   
     return 0;
}
Copy after login

Related recommendations:

cocos2dx template container is simple to use (Vector, Map, Value)

php realizes reading the memory sequence number, php Reading memory sequence

The above is the detailed content of How to set up a sequential container. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template