C++ deque(double-ended-queue)双端队列
来源:互联网 发布:淘宝童装店名大全 编辑:程序博客网 时间:2024/05/21 17:50
ostream_iterator输出流迭代器模板的使用,选自MSDN
#include <iterator>//迭代器头文件#include <vector>//向量容器头文件#include <iostream>using namespace std;int main(void){ // ostream_iterator for stream cout ostream_iterator<int> intOut ( cout , "\n" ); *intOut = 10; intOut++; *intOut = 20; intOut++; *intOut = 30; cout<<endl; int i; vector<int> vec; for ( i = 1 ; i < 7 ; ++i ) { vec.push_back ( i ); } // Write elements to standard output stream cout << "Elements output without delimiter: "; copy ( vec.begin ( ), vec.end ( ), ostream_iterator<int> ( cout ) ); cout << endl <<endl; // Write elements with delimiter " : " to output stream cout << "Elements output with delimiter: "; copy ( vec.begin ( ), vec.end ( ), ostream_iterator<int> ( cout, " : " ) ); cout << endl <<endl; system("pause");}
deque容器的使用关于deque容器类详见MSDN
#include <iostream> #include <deque>//使用双端队列是使用的头文件 #include <string> #include <algorithm>//STL中重要的头文件,提供了大量基于迭代器的非成员模版函数 using namespace std; int main(void){ deque<string> strDeq; strDeq.assign(4,string("liaoning"));//将4个字符串对象插入到队列中 strDeq.push_back("first_string"); strDeq.push_front("last_string"); copy(strDeq.begin(),strDeq.end(),ostream_iterator<string>(cout,"--")); cout << endl<< endl; for(int i = 0; i<strDeq.size(); ++i)//输出方式1{ cout << "strDeq[" << i << "] : " << strDeq[i] << endl;} cout << endl; for(i = 0;i < strDeq.size();++i)//输出方式2{ cout << "strDeq.at(" << i << ") : " << strDeq.at(i) << endl; } cout << endl; strDeq.pop_front(); strDeq.pop_back();//显示首尾出队后的结果 copy(strDeq.begin(),strDeq.end(),ostream_iterator<string>(cout," ")); cout << endl; cout << endl; for(i = 0;i < strDeq.size();++i)//给队中的每个元素加上前缀{ strDeq[i] = "pre" + strDeq[i]; } copy(strDeq.begin(),strDeq.end(),ostream_iterator<string>(cout," ")); cout << endl; cout << endl; strDeq.resize(6,"cjc");//调整队列的大小,如果6大于原大小,则补齐//小于,则保留原大小 copy(strDeq.begin(),strDeq.end(),ostream_iterator<string>(cout," ")); cout << endl; cout << endl; system("pause");}
参考以及详细原理
0 0
- C++ deque(double-ended-queue)双端队列
- 双端队列(Double-ended Queue)
- STL中的deque介绍--- double-ended queue
- Python collections deque - double-ended queue ()
- Glib学习(3) 双端队列 Double-ended Queues
- 队列Queue、双端队列Deque
- Java队列Queue、双端队列Deque
- java队列Queue、双端队列Deque
- 队列Queue、双端队列Deque
- 队列Queue、双端队列Deque
- light oj 1212 - Double Ended Queue (双向队列)
- 【java】队列、优先队列、双端队列Deque、链表LinkedList、阻塞队列(Blocking queue)
- Lightoj1212——Double Ended Queue(STL)
- C++deque双端队列
- Python 内置数据结构 —— queue(队列)、deque(双端队列)
- java队列(queue & deque)方法简介
- 双端队列(deque)
- 双端队列(Deque)
- 制作uImage镜像 .
- AOJ661 跨越千山万水只为找到你
- eclipse导入系统签名
- 如何应用ul、li标签 创建css横向导航菜单?
- 博客开通
- C++ deque(double-ended-queue)双端队列
- ubuntu RPM should not be used directly install RPM packages, use Alien instead!
- source insight 快捷键
- gdb基本命令
- leetcode: Longest Palindromic Substring
- DIV CSS布局实例:用css网站布局之十步实录!(目录)
- 博弈树取球博弈问题
- POJ 1236 Network of Schools 强连通分量
- 《算法概论》思维导图