STL容器

//vector
//变长数组,倍增思想
//string,substr()
//queue,push(),front(),pop()
//priority_queue,优先队列,push(),top(),pop()
 //stack ,栈,push(),top(),pop()
//deque ,双端队列,队头队尾都可以插入
//set,map,multiset,multimap,基于平衡二叉树(红黑树)
//unordered_set,unordered_map,unordered_multiset,unordered_multimap
//bitset

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>

using namespace std;
int main()
{
    vector<int> a(10);//vector定义
    //vector<int> a(10,3),定义一个长度为10的数组,每个值为3
    a.size();//长度
    a.empty();//是否为空
    a.clear();//清空
    a.front();//返回第一个数
    a.back();//返回最后一个数
    a.push_back();//在最后面插入一个数
    a.pop_back(); //删除最后一个数
    a.begin();//第一个数的位置
    a.end();//最后一个数的位置
    
    //遍历的方法
    for(int i = 0;i < 10;i++)a.push_back(i);
    
    for(int i= 0;i < 10;i++)cout<<a[i]<<" ";
    cout<<endl;
    
    for(vector<int>::iterator i = a.begin();i != a.end();i++)cout<<*i<<" ";//vector<int>::iterator可以用auto代替
    cout<<endl;
    
    for(auto x:a)cout<<x<<" ";
    cout<<endl;
    
    pair<int ,string>p;//定义一个二元组
    pair<int ,pair<int,int>>x;//可以存放三个
    
    p = make_pair(10,"mtq");
    p = {20,"abc"};
    
    queue<int>b;//队列
    b.size();
    b.empty();
    b.push();
    b.pop();
    b.back();
    b.front();
    
    priority_queue<int>heap;//优先队列 ,默认为大根堆
    //priority_queue<int,vector<int>,greater<int>>heap;小根堆
    heap.clear();
    heap.push();
    heap.pop();
    
    stack//栈
    push();
    pop();
    top();
    empty();
    size();
    
    deque//双端队列
    push_back();
    pop_back();
    push_front();
    pop_front();
    pop();
    top();
    empty();
    size();
    []
    
    set<int>s;//不能有重复元素
    multiset<int>ms;//可以有重复元素
    size();
    empty();
    clear();
    
    insert();
    find();
    count();//返回某个数的个数
    erase(x);//删除所有的x
    lower_bound();//返回大于等于x的最 小的数
    upper_bound();//返回小于等于x 的最大的数
    
    map
    multimap
    size();
    empty();
    clear();
    begin();
    end();
    insert(x);//插入的数是一个pair
    erase();
    find();
    []
    
    biset
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七七七_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值