deque双端队列的基本操作
2015-10-12 21:07
537 查看
#include <iostream>
using namespace std;
#include<deque>
#include <algorithm>
void printD(deque<int> &d)
{
for(deque<int>::iterator it=d.begin();it!=d.end();it++)
{
cout<<*it<<" ";
}
}
//双端数组
int main()
{
deque<int> d1;
d1.push_back(1);
d1.push_back(3);
d1.push_back(5);
d1.push_front(-11);
d1.push_front(-33);
d1.push_front(-55);
cout<<"头部元素:"<<d1.front()<<endl;
cout<<"尾部元素"<<d1.back()<<endl;
printD(d1);
cout<<endl;
d1.pop_front();
d1.pop_back();
printD(d1);
cout<<endl;
//查找-33在数组中下标值
deque<int>::iterator it=find(d1.begin(),d1.end(),-33);
if(it!=d1.end())
{
cout<<"-33的数组下标:"<<distance(d1.begin(),it)<<endl;
}
else
{
cout<<"没有找到值为-33的元素"<<endl;
}
system("pause");
return 0;
}
using namespace std;
#include<deque>
#include <algorithm>
void printD(deque<int> &d)
{
for(deque<int>::iterator it=d.begin();it!=d.end();it++)
{
cout<<*it<<" ";
}
}
//双端数组
int main()
{
deque<int> d1;
d1.push_back(1);
d1.push_back(3);
d1.push_back(5);
d1.push_front(-11);
d1.push_front(-33);
d1.push_front(-55);
cout<<"头部元素:"<<d1.front()<<endl;
cout<<"尾部元素"<<d1.back()<<endl;
printD(d1);
cout<<endl;
d1.pop_front();
d1.pop_back();
printD(d1);
cout<<endl;
//查找-33在数组中下标值
deque<int>::iterator it=find(d1.begin(),d1.end(),-33);
if(it!=d1.end())
{
cout<<"-33的数组下标:"<<distance(d1.begin(),it)<<endl;
}
else
{
cout<<"没有找到值为-33的元素"<<endl;
}
system("pause");
return 0;
}
相关文章推荐
- 关于'NSConcreteMutableAttributedString initWithString:: nil value'
- hdu 1806 Frequent values(RMQ)
- 自定义UI的基本结构
- 【UIPickerView自定义选择器控件】
- 快速排序学习 the c programming languish
- [UIView numberofRowsInSection]unrecognized selector sent to instance 0x1808bef0 错误
- Android 4.0 ICS SystemUI浅析——StatusBar结构分析
- UVA(348)——Optimal Array Multiplication Sequence(区间dp)
- UITableView
- UILabel 使用解析
- 3.集--LinkedTransferQueue得知
- poj1947 Rebuilding Roads
- ios UITextView 计算文字内容大小
- Brackets sequence
- LinearLayout布局中如何让控件置底
- 对UIBackBarButtonItem的理解
- 【四】 Chrome的UI绘制
- UITextField 解析大全
- Android UI:机智的远程动态更新策略
- JSF request参数传递