zoukankan      html  css  js  c++  java
  • 双端队列

    //插入元素//
    #include<iostream> #include<deque> using namespace std; int main() { deque<int> d; d.push_back(1);//尾部插入 d.push_back(2); d.push_back(3); d.push_front(10);//d.insert(d.begin()+1, 10);头部插入 d.push_front(20);//d.insert(d.begin()+2, 20); cout<<d[0]<<" "<<d[1]<<" "<<d[2]<<endl; return 0; }
    //遍历//
    #include<iostream> #include<deque> using namespace std; int main() { deque<int> d; d.push_back(1); d.push_back(2); d.push_back(3); for(int i = 0; i < d.size(); i ++) cout<<d[i]<<" "; cout<<endl; deque<int>::iterator it; for(it = d.begin(); it != d.end(); it ++) cout<<*it<<" "; cout<<endl; deque<int>::reverse_iterator rit; for(rit = d.rbegin(); rit != d.rend(); rit ++) cout<<*rit<<" ";//反向遍历 cout<<endl; return 0; }
    //删除//
    #include<iostream> #include<deque> using namespace std; int main() { deque<int> d; for(int i = 1; i < 6; i ++) d.push_back(i); d.pop_front(); d.pop_front(); deque<int>::iterator it; for(it = d.begin(); it != d.end(); it ++) cout<<*it<<" "; cout<<endl; d.pop_back(); for(it = d.begin(); it != d.end(); it ++) cout<<*it<<" "; cout<<endl; d.erase(d.begin()+1); for(it = d.begin(); it != d.end(); it ++) cout<<*it<<" "; cout<<endl; d.clear(); cout<<d.size()<<endl; return 0; }
  • 相关阅读:
    POJ 1201 Intervals 差分约束
    netframework2.0,asp.net2.0,vs.net 2005
    学习.net第一天
    VS.NET 2003 控件命名规范
    .Net生成共享程序集
    汉字的编码
    [转]用C#实现连接池
    SQL表自连接用法
    一道很好玩的OOP面试题,今天比较有空,所有做了一下
    C#编程规范(2008年4月新版)
  • 原文地址:https://www.cnblogs.com/xlqtlhx/p/6130029.html
Copyright © 2011-2022 走看看