zoukankan      html  css  js  c++  java
  • cb48a_c++_STL_算法_重排和分区random_shuffle_stable_partition

    cb48a_c++_STL_算法_重排和分区random_shuffle_stable_partition
    random_shuffle()//重排,随机重排,打乱顺序
    partition()分区,把符合规则的分成两个区域,比如奇数放一边,偶数放一边.默认之间的位置会变化
    stable_partition(),稳定的分区,分区后,默认之间的位置不会变化,
    比如:2,3,5,6,分区后,2依然在6的前面。3依然在5的前面
    
    
    STL算法--变序性算法
    reverse() 逆转
    reverse_copy()一边复制一般逆转
    rotate()旋转,某个位置开始前后交换位置
    rotate(ivec2.begin(), ivec2.begin() + 2, ivec2.end());
    1,2,3,4,5,6,7,8,9,
    rotate后:
    3,4,5,6,7,8,9,1,2,
    
    rotate_copy()一边复制一般旋转
    
    、、、
    next_permutation()
    prev_permutation()
    random_shuffle()
    partition()
    stable_partition()
    /*cb48a_c++_STL_算法_重排和分区random_shuffle_stable_partition
    random_shuffle()//重排,随机重排,打乱顺序
    partition()分区,把符合规则的分成两个区域,比如奇数放一边,偶数放一边.默认之间的位置会变化
    stable_partition(),稳定的分区,分区后,默认之间的位置不会变化,
    比如:2,3,5,6,分区后,2依然在6的前面。3依然在5的前面
    
    
    STL算法--变序性算法
    reverse() 逆转
    reverse_copy()一边复制一般逆转
    rotate()旋转,某个位置开始前后交换位置
    rotate(ivec2.begin(), ivec2.begin() + 2, ivec2.end());
    1,2,3,4,5,6,7,8,9,
    rotate后:
    3,4,5,6,7,8,9,1,2,
    
    rotate_copy()一边复制一般旋转
    
    、、、
    next_permutation()
    prev_permutation()
    random_shuffle()
    partition()
    stable_partition()
    
    */
    
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <functional>
    
    using namespace std;
    
     template < typename TT5>
     void print1(TT5 &ilist)
     {
            for (TT5::iterator iter = ilist.begin(); iter != ilist.end(); ++iter)
                 {
                     cout << *iter << ' ';
            
                    }
        cout << endl;
         }
    
    int main()
    {
        vector<int> ivec,ivec2,ivec3;
        for (int i = 1; i <= 9; ++i)
        {
            ivec.push_back(i);
            
        }
        ivec3 = ivec2 = ivec;
        print1(ivec);
    
        random_shuffle(ivec.begin(),ivec.end());
        cout << "重排后:" << endl;
        print1(ivec);
        cout << "ivec2一般分区前:" << endl;
        print1(ivec2);
        
    
        cout << "分区演示:偶数放左,奇数放右边" << endl;
    
    
        //预定义函数对象:not1(bind2nd(modulus<int>(), 2))
        //https://blog.csdn.net/txwtech/article/details/104383237
        partition(ivec2.begin(), ivec2.end(), not1(bind2nd(modulus<int>(), 2)));
        cout << "ivec2一般分区后:" << endl;
        print1(ivec2);
    
        cout << "稳定分区前ivec3:" << endl;
        print1(ivec3);
    
        stable_partition(ivec3.begin(), ivec3.end(), not1(bind2nd(modulus<int>(), 2)));
        cout << "稳定分区后ivec3:" << endl;
        print1(ivec3);
        return 0;
    }
  • 相关阅读:
    MapReduce 中的Map后,sort不能对中文的key排序
    wordCount程序中MapReduce工作过程分析
    使用eclipse的快捷键自动生成的map或者reduce函数的参数中:“org.apache.hadoop.mapreduce.Reducer.Context context”
    "hadoop namenode -format"命令的作用和影响的文件
    伪分布模式下使用java接口,访问hdfs
    MySQL Server 5.5.44免安装版配置详解
    quartz Cron表达式一分钟教程
    【转载】jQuery弹出层始终垂直居中于当前屏幕
    LeetCode 151 翻转字符串里的单词
    LeetCode 43 字符串相乘
  • 原文地址:https://www.cnblogs.com/txwtech/p/12365880.html
Copyright © 2011-2022 走看看