zoukankan      html  css  js  c++  java
  • deque双端队列(常用方法总结)

     1 /*关于C++ STL中deque的学习*/ 
     2 #include<cstdio>
     3 #include<iostream>
     4 #include<deque>
     5 
     6 using namespace std;
     7 void print(deque<int> d);
     8 void rprint(deque<int> d);
     9 int main()
    10 {
    11     deque<int> dq;
    12     dq.push_back(1);
    13     dq.push_back(2);
    14     dq.push_back(3);
    15     dq.push_back(4);
    16     cout<<dq.size()<<endl;
    17     cout<<dq[0]<<" "<<dq[1]<<" "<<dq[2]<<" "<<dq[3]<<endl;
    18     
    19     dq.push_front(0);
    20     cout<<dq.size()<<endl;
    21     cout<<dq[0]<<" "<<dq[1]<<" "<<dq[2]<<" "<<dq[3]<<" "<<dq[4]<<endl;
    22     
    23     dq.insert(dq.begin()+2,8);
    24     cout<<dq.size()<<endl;
    25     cout<<dq[0]<<" "<<dq[1]<<" "<<dq[2]<<" "<<dq[3]<<" "<<dq[4]<<" "<<dq[5]<<endl;
    26     
    27     cout<<"##"<<endl;
    28     print(dq);
    29     dq.pop_front();
    30     print(dq);
    31     
    32     print(dq);
    33     dq.pop_back();
    34     print(dq);
    35     
    36     print(dq);
    37     dq.clear();
    38     cout<<"##"<<endl;
    39     print(dq);
    40     cout<<"##"<<endl;
    41     return 0;
    42 }
    43 
    44 void print(deque<int> d){
    45     for(int i=0;i<d.size();i++){
    46         printf("%d ",d[i]);
    47     }
    48     puts("");
    49 }
    50 
    51 void rprint(deque<int> d){
    52     for(int i=d.size()-1;i>=0;i--){
    53         printf("%d ",d[i]);
    54     }
    55     puts("");
    56 }
  • 相关阅读:
    Unity3D笔记十六 输入输出-键盘事件、鼠标事件
    Unity3D笔记十五 碰撞、移动
    Unity3D笔记十四 力
    Unity3D笔记十三 摄像机之间切换
    the pointer this
    argc[] and *argv[]
    Square Detector
    pointer1
    OpenCV1
    OpenCV
  • 原文地址:https://www.cnblogs.com/wenzhixin/p/9129773.html
Copyright © 2011-2022 走看看