zoukankan      html  css  js  c++  java
  • STL-deque 双端数组简析

     1 #include <iostream>
     2 #include <deque>
     3 
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     // 插入
     9     deque<int> de;
    10     for(int i=0;i<5;++i)
    11     {
    12         de.push_back(i);
    13     }
    14 
    15     for(int i=1;i<=5;++i)
    16     {
    17         de.push_front(i*10);
    18     }
    19 
    20     for(deque<int>::iterator it=de.begin();it!=de.end();++it)
    21     {
    22         cout<<*it<<" ";
    23     }
    24     cout<<endl;
    25 
    26     // 删除
    27     de.pop_back();
    28     de.pop_front();
    29     for(deque<int>::iterator it=de.begin();it!=de.end();++it)
    30     {
    31         cout<<*it<<" ";
    32     }
    33     cout<<endl;
    34 
    35     // 求当前迭代器位置
    36     for(deque<int>::iterator it=de.begin();it!=de.end();++it)
    37     {
    38         cout<<distance(de.begin(),it)<<" ";
    39     }
    40     cout<<endl;
    41 
    42 }

    #include <iostream>#include <deque>
    using namespace std;
    int main(){    // 插入    deque<int> de;    for(int i=0;i<5;++i)    {        de.push_back(i);    }
        for(int i=1;i<=5;++i)    {        de.push_front(i*10);    }
        for(deque<int>::iterator it=de.begin();it!=de.end();++it)    {        cout<<*it<<" ";    }    cout<<endl;
        // 删除    de.pop_back();    de.pop_front();    for(deque<int>::iterator it=de.begin();it!=de.end();++it)    {        cout<<*it<<" ";    }    cout<<endl;
        // 求当前迭代器位置    for(deque<int>::iterator it=de.begin();it!=de.end();++it)    {        cout<<distance(de.begin(),it)<<" ";    }    cout<<endl;
    }

  • 相关阅读:
    es6语法快速上手(转载)
    width百分比
    利用switch case 来运行咱们结婚吧
    利用if else来运行咱们结婚吧
    利用if else 来计算车费
    利用switch case判断是今天的第多少天
    利用if else判断是否及格
    利用if,else判断输入的是不是一个正整数
    再练一遍猜拳
    用if else 判断是不是7的倍数等
  • 原文地址:https://www.cnblogs.com/jishuren/p/12238604.html
Copyright © 2011-2022 走看看