您的位置:首页 > 产品设计 > UI/UE

deque向量

2016-02-24 20:30 330 查看
#include <iostream>
#include <deque>
#include <algorithm>  // 算法的头文件,

int main()
{
using namespace std;

deque<int> a;

a.push_back(2);
a.push_back(3);

a.push_front(4);

for (size_t nCount = 0; nCount < a.size(); ++nCount)
{
cout << a[nCount] << endl;
}

cout << endl;

a.pop_front();  // 将4删除,
a.pop_back();  // 将3删除

deque<int>::iterator iElementLocater;  //iElementLocater是deque自己的迭代器,
for(iElementLocater = a.begin(); iElementLocater != a.endl();
++iElementLocater)
{
size_t nOffset = distance(a.begin(),iElementLocater);   // distance是a.begin()和iElementLocater两个迭代器之间的距离,
cout << "a[" << nOffset << "] = " << *iElementLocater << endl;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: