deque_queue_list
#include <iostream>
#include <deque>//front push pop back push pop [] at()
#include <queue>
#include <stack>
#include <list> //remove
using namespace std; void listTest()
{
int iArray[]={,,,,,,,,,,};
list<int> listInt(iArray,iArray+); list<int>::iterator it_list=listInt.begin();
for (;it_list!=listInt.end();++it_list)
{
cout<<*it_list<<" ";
}
cout<<endl;
cout<<"=============================="<<endl;
int i;
for(i=;i<;i++)// (i-=1;i>=0;--i)
{
listInt.push_front(iArray[i]);
}
/////////////////////////////////////// for(i=;i<;i++)//
{
listInt.pop_front();
}
//-----------------------------------
cout<<"pop front:"<<endl;
it_list=listInt.begin();
for (;it_list!=listInt.end();++it_list)
{
cout<<*it_list<<" ";
}
cout<<endl;
cout<<"=============================="<<endl;
//////////////////////////////////////////////// for(i-=;i>=;--i)
{
listInt.push_front(iArray[i]);
} cout<<"push front:"<<endl;
it_list=listInt.begin();
for (;it_list!=listInt.end();++it_list)
{
cout<<*it_list<<" ";
}
cout<<endl;
cout<<"=============================="<<endl; for(i=;i<;i++)//
{
listInt.pop_back();
} cout<<"pop back:"<<endl;
it_list=listInt.begin();
for (;it_list!=listInt.end();++it_list)
{
cout<<*it_list<<" ";
}
cout<<endl;
cout<<"=============================="<<endl; listInt.remove();
cout<<"remove 3:"<<endl;
it_list=listInt.begin();
for (;it_list!=listInt.end();++it_list)
{
cout<<*it_list<<" ";
}
cout<<endl;
/*
1 2 3 4 5 3 3 3 3 3 6
==============================
pop front:
1 2 3 4 5 3 3 3 3 3 6
==============================
push front:
1 2 3 4 5 3 3 3 3 3 6 1 2 3 4 5 3 3 3 3 3 6
==============================
pop back:
1 2 3 4 5 3 3 3 3 3 6
==============================
remove 3:
1 2 4 5 6
Press any key to continue
*/
} void stackTest()
{
int iArray[]={,,,,,,,,,,};
//stack<int> stackInt(iArray,iArray+11);
stack<int> stackInt;
for (int i=;i<sizeof(iArray)/sizeof(int);i++)
{
stackInt.push(iArray[i]);
} cout<<"pop~:"<<endl;
int len=stackInt.size();
for (i=;i<len;i++)
{
cout<<stackInt.top()<<" ";
stackInt.pop();
}
cout<<endl;
/*
pop~:
6 3 3 3 3 3 5 4 3 2 1
Press any key to continue
*/
} void queueTest()
{
int iArray[]={,,,,,,,,,,};
//queue<int> queueInt(iArray,iArray+11);
queue<int> queueInt;
for (int i=;i<;i++)
{
queueInt.push(iArray[i]);
}
//queue<int>::iterator it_queue=queueInt.begin();
//cout<<queueInt.end()<<endl;
////////////////////////////////
cout<<"pop~:"<<endl;
int len=queueInt.size();
for (i=;i<len;i++)
{
cout<<queueInt.front()<<" ";
queueInt.pop();
}
cout<<endl;
/*
pop~:
1 2 3 4 5 3 3 3 3 3 6
Press any key to continue
*/
} void main()
{
listTest();return;
//stackTest();return;
//queueTest();return;
int iArray[]={,,,,,,,,,,};
//deque<int> deInt(iArray,iArray+11);
deque<int> deInt;
for (int i=;i<;i++)
{
deInt.push_back(iArray[i]);
} deque<int>::iterator itorDeque=deInt.begin();
for (;itorDeque!=deInt.end();++itorDeque)
{
cout<<*itorDeque<<" ";
}
cout<<endl;
cout<<"=============================="<<endl;
for(i=;i<;i++)// (i-=1;i>=0;--i)
{
deInt.push_front(iArray[i]);
}
for(i=;i<;i++)//
{
deInt.pop_front();
}
itorDeque=deInt.begin();
for (;itorDeque!=deInt.end();++itorDeque)
{
cout<<*itorDeque<<" ";
}
cout<<endl; for(i-=;i>=;--i)
{
deInt.push_front(iArray[i]);
} cout<<"push front:"<<endl;
itorDeque=deInt.begin();
for (;itorDeque!=deInt.end();++itorDeque)
{
cout<<*itorDeque<<" ";
}
cout<<endl; for(i=;i<;i++)//
{
deInt.pop_back();
} cout<<"pop back:"<<endl;
itorDeque=deInt.begin();
for (;itorDeque!=deInt.end();++itorDeque)
{
cout<<*itorDeque<<" ";
}
cout<<endl; deInt.push_front();
cout<<"at:"<<endl;
for (i=;i<deInt.size();i++)
{
cout<<deInt.at(i)<<" ";
}
cout<<endl;
/*
1 2 3 4 5 3 3 3 3 3 6
==============================
1 2 3 4 5 3 3 3 3 3 6
push front:
1 2 3 4 5 3 3 3 3 3 6 1 2 3 4 5 3 3 3 3 3 6
pop back:
1 2 3 4 5 3 3 3 3 3 6
at:
0 1 2 3 4 5 3 3 3 3 3 6
Press any key to continue
*/ }
deque_queue_list的更多相关文章
随机推荐
- docker 学习操作记录 5-2
记录5-2 root@53d0a643a2c7:/# quit bash: quit: command not found root@53d0a643a2c7:/# exit exit -->@ ...
- Java选择结构和循环结构
1.选择结构 ①.ifif(){ } if(){}else{} if(){}else if(){}else if(){}else{} ②.switch switch (表达式) { case 常量 1 ...
- python 笔记——生成器和迭代器
#-*- coding:utf-8 -*- a=[1,2,3,4] for i,j in enumerate(a): print i,j '''只有ij时,''' a=[1,2,3,4] for i ...
- Lambda表达式和函数式编程
Lambda表达式和函数式编程 https://www.cnblogs.com/bigbigbigo/p/8422579.html https://www.runoob.com/java/java8- ...
- CXF 教程 (二)
将 Service 布署在远端 1 Overview 2 Server 3 Client 1 Overview 上例中我们的 Server 和 Client 都是在本地.下面演示如果布署在远端需如何修 ...
- docker run VS docker exec 的区别
“docker run”和“docker exec”都是 Docker 容器中用于执行的命令.然而,在不同的情况下,它们的使用有着本质上的区别. “docker run”命令 “docker run” ...
- Mysql之索引(六)
1.思考 在图书馆是怎么找到一本书的? 一般的应用系统对比数据库的读写比例在10:1左右(即有10次查询有1次写操作),而且插入操作和更新操作很少出现性能问题. 遇到最多,最复杂的还是一些复杂的查询操 ...
- 【WEB基础】HTML & CSS 基础入门(10)布局与定位
块级元素和行内元素 HTML里的元素可以分为块级元素和行内元素两大类:
- Vue事件修饰符,.capture关键字详解
.prevent 用于阻止默认事件,点击a标签href可以打开相应的链接,那么给事件加 上此关键字,click.prevent .capture 冒泡顺序 例如 div1中嵌套div2中嵌 ...
- Java JDBC结果集的处理
结果集指针的移动 while (resultSet.next()){ //...... } 指针最初指向第一条记录之前,next()是指向下一个位置,返回的是boolean值,true表示有内容(记录 ...