目录
queue
queue简单介绍
queue举例
#include<bits/stdc++.h>
//#include<queue>
using namespace std;
queue<int>q;
int main()
{
q.push(12);//加入队列
q.push(1);
q.push(5);
q.push(9);
cout<<q.size()<<endl;
while(!q.empty())//非空
{
printf("%d\n",q.front());//队首
q.pop();//弹出
}
}
stack
stack用法
示例
#include<bits/stdc++.h>
//#include<stack>
using namespace std;
stack<int>q;
int main()
{
q.push(12);//加入栈
q.push(1);
q.push(5);
q.push(9);
cout<<q.size()<<endl;
while(!q.empty())//非空
{
printf("%d\n",q.top());//栈顶
q.pop();//弹出
}
}
vector
函数介绍
用法示例
#include<bits/stdc++.h>
//#include<vector>
using namespace std;
vector<int>v;
int main()
{
for(int i=10;i>=0;i--)
v.push_back(i);
printf("init:");
for(int i=0;i<v.size();i++)
{
printf("%d ",v[i]);
}
sort(v.begin(),v.end());
cout<<endl;
for(int i=0;i<v.size();i++)
{
printf("%d ",v[i]);
}
}
deque
#include<bits/stdc++.h>
using namespace std;
deque<int>dq;
int main()
{
dq.push_back(1);
dq.push_back(2);
dq.push_back(3);//插入队尾
dq.push_front(0);//插入队首
while(!dq.empty())
{
printf("%d ",dq.front());//首
dq.pop_front();//pop首
}
printf("\n");
dq.push_back(1);
dq.push_back(2);
dq.push_back(3);
dq.push_front(0);
while(!dq.empty())
{
printf("%d ",dq.back());//尾
dq.pop_back();//pop尾
}
}