STL_算法(26)_重排和分区 random_shuffle() ;partition() ;stable_partion()
来源:互联网 发布:java验证码工具类 编辑:程序博客网 时间:2024/06/06 09:06
random_shuffle()
partition()
stable_partion()
#include<iostream>#include<algorithm>#include<vector>using namespace std;int main(){vector<int> ivec;for(int i = 0; i <= 9; i++)ivec.push_back(i);for(vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); iter++)cout<<*iter<<' ';cout<<endl;random_shuffle(ivec.begin(), ivec.end());for(vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); iter++)cout<<*iter<<' ';cout<<endl;//system("pause");return 0;}
#include<iostream>#include<algorithm>#include<vector>//#include<functional>using namespace std;int main(){vector<int> ivec;vector<int> ivec2;vector<int> ivec3;for(int i = 1; i <= 9; i++){ivec.push_back(i);ivec2.push_back(i);ivec3.push_back(i);}for(vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); iter++)cout<<*iter<<' ';cout<<endl;random_shuffle(ivec.begin(), ivec.end());for(vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); iter++)cout<<*iter<<' ';cout<<endl;cout<<endl;for(vector<int>::iterator iter = ivec2.begin(); iter != ivec2.end(); iter++)cout<<*iter<<' ';cout<<endl;// partition 是不稳定的分区算法vector<int>::iterator pos1;pos1 = partition(ivec2.begin(), ivec2.end(), not1(bind2nd(modulus<int>(), 2)));for(vector<int>::iterator iter = ivec2.begin(); iter != ivec2.end(); iter++)cout<<*iter<<' ';cout<<endl;for(vector<int>::iterator iter = ivec3.begin(); iter != ivec3.end(); iter++)cout<<*iter<<' ';cout<<endl;vector<int>::iterator pos2;pos2 = stable_partition(ivec3.begin(), ivec3.end(), not1(bind2nd(modulus<int>(), 2)));// statble_partition()是不稳定的算法for(vector<int>::iterator iter = ivec3.begin(); iter != ivec3.end(); iter++)cout<<*iter<<' ';cout<<endl;//system("pause");return 0;}
0 0
- STL_算法(26)_重排和分区 random_shuffle() ;partition() ;stable_partion()
- STL_算法_重排和分区(random_shuffle、partition、stable_partition)
- STL_算法_最小值和最大值(min_element、max_element)
- STL_算法(28)_局部排序
- C++ STL 算法:重排和分区
- STL_算法(22)_ STL_算法_替换算法
- STL_算法(24)_删除_(2)
- STL_算法(24)_删除_(3)uinique() unique_copy()
- STL_算法(21)_ STL_算法_填充新值
- STL_算法(25)_逆转和旋转 revers() 、reverse_copy()、rotate()、rotate_copy()、
- random_shuffle 和transform算法
- STL_算法_交换(swap_ranges)
- STL_算法_查找算法(find、find_if)
- STL_算法_查找算法(search、find_end)
- STL_算法(16)_复制元素 copy() copy_backward()
- STL_算法(17)_排列组合 next_permutation() perv_permutation()
- 重排算法与分区算法
- STL_算法(23)_删除_(1)
- Effective Modern C++ 条款27 熟悉替代重载通用引用的方法
- crontab命令格式说明
- 这么做,真的可以吗?
- 错题整理之网络(二)
- 华为oj--字符串截取(最长回文字符串)
- STL_算法(26)_重排和分区 random_shuffle() ;partition() ;stable_partion()
- Java 学习笔记(0x05) 继承
- 六大设计原则
- Android四大组件之一——Activity
- 解决React Native的Image组件中不更新图片的问题
- 2016-09-02
- Android 摆动的球体
- uCOSIII学习笔记之OSCtrSW( )
- ubuntu下如何看我的显卡驱动是否装好了(转自 雪谦信的博客)