• cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort


    cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort
    sort(b,e)
    sort(b,e,p)
    stable_sort(b,e)
    stable_sort(b,e,p)
    
    注意:
    不适用于list容器,list有成员函数sort();
    cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort
    sort(b,e)
    sort(b,e,p)
    stable_sort(b,e) //stirng,按字符个数排序.能够保证位置间前面一致。比如 22 33 55. 555, 如果按个数排序, 22能够保证一直在33前。
    stable_sort(b,e,p)//


    /*cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort
    sort(b,e)
    sort(b,e,p)
    stable_sort(b,e)
    stable_sort(b,e,p)
    
    注意:
    不适用于list容器,list有成员函数sort();
    */
    
    #include <iostream>
    #include <algorithm>
    #include <functional>
    #include <vector>
    #include <deque>
    
    using namespace std;
    
    template <typename TT9>
    void print9(TT9 &ideq)
    {
        for (TT9::iterator iter = ideq.begin(); iter != ideq.end(); ++iter)
            cout << *iter << ' ';
        cout << endl;
    }
    
    int main()
    {
        deque<int> ideq;
    
        for (int i = 1; i <= 9; ++i)
            ideq.push_back(i);
        for (int i = 1; i <= 9; ++i)
            ideq.push_back(i);
        print9(ideq);
    
        sort(ideq.begin(),ideq.end());
        cout << "默认是less,从小到大排序后: " << endl;
        print9(ideq);
    
        //sort(ideq.begin(), ideq.end(),less<int>());//默认是less,从小到大排列
        sort(ideq.begin(), ideq.end(),greater<int>());//从大到小
        cout << "从大到小排序后: " << endl;
        print9(ideq);
    
    
        return 0;
    }
    /*cb49a_c++_STL_算法_对所有元素排序_sort_stable_sort
    sort(b,e)
    sort(b,e,p)
    stable_sort(b,e) //stirng,按字符个数排序.能够保证位置间前面一致。比如 22 33 55. 555, 如果按个数排序, 22能够保证一直在33前。
    stable_sort(b,e,p)//
    
    注意:
    不适用于list容器,list有成员函数sort();
    */
    
    #include <iostream>
    #include <algorithm>
    #include <functional>
    #include <vector>
    #include <string>
    
    using namespace std;
    
    template <typename TT9>
    void print9(TT9 &ideq)
    {
        for (TT9::iterator iter = ideq.begin(); iter != ideq.end(); ++iter)
            cout << *iter << ' ';
        cout << endl;
    }
    bool lessLength(const string &s1, const string &s2)
    {
        return s1.length() < s2.length();
    }
    
    int main()
    {
        vector<string> svec;
        vector<string> svec2;
        svec.push_back("1xxxx");
        svec.push_back("2x");
        svec.push_back("3x");
        svec.push_back("4x");
        svec.push_back("5xx");
        svec.push_back("6xxxx");
        svec.push_back("7xx");
        svec.push_back("8xxx");
        svec.push_back("9xx");
        svec.push_back("10xxx");
        svec.push_back("11");
        svec.push_back("17");
        svec.push_back("12");
        svec.push_back("13");
        svec.push_back("14xx");
        svec.push_back("15");
        svec.push_back("16");
        
    
        svec2 = svec;
        print9(svec);
    
        sort(svec.begin(), svec.end(), lessLength);
        print9(svec);
    
        cout << "稳定的排序:" << endl;
        //stable_sort(b, e, p)//
        stable_sort(svec2.begin(), svec2.end(), lessLength);
        print9(svec2);
    
    
    
        return 0;
    }
  • 相关阅读:
    vue create is a Vue CLI 3 only command and you are using Vue CLI 2.9.6. You
    Vue2.x是怎么收集依赖的
    只绑定一次事件的简单方法
    Proxy是怎么做数据劫持的
    使用babel进行打包
    使用npm link进行模块调试
    Webpack 热加载插件的实现原理
    Vue 服务端渲染的数据流
    Vue的生命周期钩子
    Linux定时任务
  • 原文地址:https://www.cnblogs.com/txwtech/p/12366186.html
Copyright © 2020-2023  润新知