zoukankan      html  css  js  c++  java
  • 15stl模板

    1.stack

    #include<iostream>
    #include<stdio.h>
    #include<stack>
    using namespace std;
    
    int main(){
        stack<int>mystack;//
        mystack.push(16);//插入元素
        mystack.push(64);
        mystack.push(32);
        printf("大小:%d
    ",mystack.size());//大小
    
        while(!mystack.empty()){//非空
            printf("%d
    ",mystack.top());//栈顶元素
            mystack.pop();//栈顶出栈
        }
    
        return 0;
    }
    View Code

    2.queue

    #include<iostream>
    #include<stdio.h>
    #include<queue>
    using namespace std;
    
    int main(){
        queue<int>myqueue;//
        myqueue.push(16);//插入元素
        myqueue.push(64);
        myqueue.push(32);
        printf("大小:%d
    ",myqueue.size());//大小
    
        while(!myqueue.empty()){//非空
            printf("%d
    ",myqueue.front());//队首元素
            myqueue.pop();//队首出队
        }
    
        return 0;
    }
    View Code

    3.priority_queue

    #include<iostream>
    #include<stdio.h>
    #include<queue>
    using namespace std;
    
    int main(){
        priority_queue<int>mypq;//
        mypq.push(16);//插入元素
        mypq.push(64);
        mypq.push(32);
        printf("大小:%d
    ",mypq.size());//大小
    
        while(!mypq.empty()){//非空
            printf("%d
    ",mypq.top());//队首元素
            mypq.pop();//队首出队
        }
    
        return 0;
    }
    View Code

    4.vector

    #include<iostream>
    #include<stdio.h>
    #include<vector>
    using namespace std;
    
    int main(){
        vector<int>myvector;//
        myvector.push_back(16);//在最后插入元素
        myvector.push_back(64);
        myvector.push_back(32);
        printf("大小:%d
    ",myvector.size());//大小
    
        vector<int>::iterator it;//迭代器
        for(it=myvector.begin();it!=myvector.end();++it){//开头到结尾
            printf("%d
    ",*it);
        }
    
        return 0;
    }
    View Code

    5.set

    #include<iostream>
    #include<stdio.h>
    #include<set>
    using namespace std;
    
    //以类为比较器
    struct classCompare{
        bool operator()(const int &a,const int &b)const{
            return a>b;//降序
        }
    };
    //以指针函数为比较器
    bool cmp(int a,int b){
        return a>b;//降序
    }
    
    int main(){
        //
        set<int>myset;//默认升序
    
        //set<int,classCompare>myset;//降序
    
        //bool(*p)(int,int)=cmp;
        //set<int,bool(*)(int,int)>myset(p);//降序
    
        myset.insert(16);//插入元素
        myset.insert(64);
        myset.insert(32);
        printf("大小:%d
    ",myset.size());//大小
    
        set<int>::iterator it;//迭代器
        for(it=myset.begin();it!=myset.end();++it){//开头到结尾
            printf("%d
    ",*it);
        }
    
        return 0;
    }
    View Code

    6.map

    #include<iostream>
    #include<stdio.h>
    #include<map>
    using namespace std;
    
    int main(){
        map<char,int>mymap;//
        mymap['b']=16;//插入元素
        mymap.insert(pair<char,int>('a',64));
        mymap.insert(pair<char,int>('c',32));
        printf("大小:%d
    ",mymap.size());//大小
    
        map<char,int>::iterator it;//迭代器
        for(it=mymap.begin();it!=mymap.end();++it){//开头到结尾
            printf("%c %d
    ",it->first,it->second);
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    镜像切换Logreader Agent报错:分发数据库中可能存在不一致的状态(续)
    镜像切换Logreader Agent报错:分发数据库中可能存在不一致的状态
    SQL优化案例—— RowNumber分页
    SQL Server 服务器磁盘测试之SQLIO篇(二)
    SQL Server 服务器磁盘测试之SQLIO篇(一)
    SQL Server内存遭遇操作系统进程压榨案例
    git添加ssh公钥报错
    leetcode_1187. Make Array Strictly Increasing 使数组严格递增_[DP]
    leetcode_1293. Shortest Path in a Grid with Obstacles Elimination_[dp动态规划]
    leetcode_1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold_[二维前缀和]
  • 原文地址:https://www.cnblogs.com/gongpixin/p/4739900.html
Copyright © 2011-2022 走看看