/*
常用STL
*/
# include <iostream>
# include <string.h>
# include <string>
# include <algorithm>
# include <stdio.h>
# include <queue>
# include <map>
# include <set>
using namespace std;
typedef struct Node
{
int val;
bool operator < (const Node &A) const
{
return val < A.val;
}
}Node;
int main()
{
//双向队列 deque
deque<int > que;
que.push_back(2);//往队列后面插入
que.push_front(1);// 往队列前面插入
que.pop_back();//队尾出队
que.pop_front();//队首出队
que.empty();//队列是否为空
//set
set<Node > st;
set<Node > :: iterator iter;
Node a,b;
a.val = 7;
b.val = 2;
st.insert(a);
st.insert(b);
iter = st.begin();
cout << (*iter).val<<endl;//输出2
//vector 常用作图的邻接表
vector<int> vt;
vector<int> :: iterator iter1;
vt.push_back(1);
vt.clear();//删除所有元素
vt.push_back(2);
iter1 = vt.begin();
vt.erase(iter1);// 删除iter1指向的元素
cout << vt.size()<<endl;
//make_heap
vector<int > vt;
make_heap(vt.begin(),vt.end());//堆排序
vt.push_back(1);
push_heap(vt.begin(),vt.end())//对新加入的元素进行堆排序
//priority_queue 优先队列:按照优先级进行出队
priority_queue<int > pq;
pq.push(1);
pq.pop();
pq.top();
/*
struct cmp
{
bool operator()(int x,int y)
{
return x > y;
}
};
*/
priority_queue<int,vector<int>,cmp > pq;//自定义比较规则
//map 的使用
map<int,string> mp;
mp[0] = "000";
mp[1] = "111";
cout <<mp[1]<<endl;
return 0;
}
常用STL
最新推荐文章于 2024-08-27 11:04:06 发布