• pair node stack vector string priority_queue


     map

    
    

    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    map<char,string> mp;
    signed main() {
        ios::sync_with_stdio(0);
        mp['0'] = "0000";mp['1'] = "0001";mp['2'] = "0010";
        mp['A'] = "1010";
    
        map<char,string> :: iterator it;
        for(it = mp.begin(); it != mp.end();it++)
            cout << it->first << " " << it->second << endl;
        cout << "倒序遍历:
    ";
        for(auto t = --mp.end();;t--){
            cout << t->first << " " << t->second << endl;
            if(t == mp.begin()) break;
        }
        cout << "auto的遍历:
    ";
        for(auto itt : mp)
            cout << itt.first << " " << itt.second << endl;
    
        return 0;
    }
    View Code

    vector

    #include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    vector<int> v;
    int main(){
        if(v.empty())
            puts("v is empty");
        for(int i = 0; i < 10; i ++)
            v.push_back(i);
        cout << v.size() << endl;
        v.insert(v.begin() + 9, 10);//在第10个元素前面插入10
        v.push_back(10);//尾部插入10
        for(int i = 0; i < v.size(); i++)
            cout << v[i] << " ";
        cout << endl;
        v.erase(v.begin() + 9);//删除第10个
        v.pop_back();//删除末尾
        for(int i = 0; i < v.size(); i++)
            cout << v[i] << " ";
        cout << endl;
        reverse(v.begin(),v.end());//反转
        for(int i = 0; i < v.size(); i++)
            cout << v[i] << " ";
        cout << endl;
        sort(v.begin(),v.end());
        for(int i = 0; i < v.size(); i++)
            cout << v[i] << " ";
        return 0;
    }
    View Code

    在这里插入图片描述
    v [ n ]
    返回 v 中位置为 n 的元素。
    push_back() 在数组的最后添加一个数据
    pop_back() 去掉数组的最后一个数据
    begin() 得到数组头的指针
    end() 得到数组的最后一个单元+1的指针
    empty() 判断vector是否为空
    swap() 与另一个vector交换数据

    string

    长度str.length(), str.size()
    比较 str1.compare(str2)
    查找 pos = str1.find(str2)
    连接 str1 += str2
    插入 str1.insert(pos,str2)
    替换 str1.replace(pos,n,str2)
    删除 str1.erase(pos,len)
    清除 str.clear()
    判空 str.empty()
    反转 reverse(s.begin(),s.end())
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int main(){
        string str1,str2,str3;
        str1 = "Hello";
        str2 = "World";
       
      
    
        cout << str1.insert(2,str2) << endl;
        cout << str1 << endl;
        cout << str1.replace(0,1,str2) << endl;//从下标0开始的1个用str2替换
        cout << str3 << endl;
        cout << str3.find("World") << endl;
        cout << str3.erase(2,3)<< endl;
        cout << str3 << endl;
        reverse(str3.begin(),str3.end());
        cout << str3 << endl;
    
    
    
    }
    

    vector 和string基本差不多

    priority_queue

    建立的时间复杂度O(n)
    插入删除时间复杂度O(log n)

    升序

    priority_queue<int,vector<int>,greater<int>> que;
    

    降序

    priority_queue<int> que;
    

    与普通队列
    同:在队尾插入,队头删除
    异:队列中最大元素总是在队头(这也就是说,出队列不是按照先进先出,而是按照元素大小,从大到小出去)

  • 相关阅读:
    oc kvc的模式:匹配搜索模式(模式匹配)、装包解包
    编程语言的多态与动态
    swift的@objc总结
    swift函数的调用约定
    PHP实现微信退款的分析与源码实现
    【MySQL】20个经典面试题,全部答对月薪10k+
    redis面试题总结
    【Redis缓存机制】1.Redis介绍和使用场景
    php四种文件加载语句
    做网站-mysql表字段设计
  • 原文地址:https://www.cnblogs.com/xcfxcf/p/12301581.html
Copyright © 2020-2023  润新知