STL算法排列
来源:互联网 发布:认识linux服务器 编辑:程序博客网 时间:2024/06/05 14:15
《C++ Primer》
//所有容器适用
next_permutation(b,e) //下一个排列-----从小到大 返回值false,表示没有下一个next_permutation(b,e,cp)
prev_permutation(b,e) //上一个排列-----从大到小 返回值true,表示还有下一个
prev_permutation(b,e,cp)
在使用排列的时候,必须先排列,要么从打到小,要么从小到大
/**------http://blog.csdn.net/u010579068------**/ #include<iostream> #include<cstdio> #include<string> #include<vector> #include<list> #include<deque> #include<algorithm> using namespace std; /***************************************** //所有容器适用 next_permutation(b,e) //下一个排列-----从小到大 返回值false,表示没有下一个 next_permutation(b,e,cp) prev_permutation(b,e) //上一个排列-----从大到小 返回值true,表示还有下一个 prev_permutation(b,e,cp) *****************************************/ /**---------------------------------------------------------------------------------- ----------------------------------------------------------------------------------**/ /************************************************************************************* std::next_permutation 所有排序容器适用 algorithm -------------------------------------------------------------------------------------- template <class BidirectionalIterator> bool next_permutation (BidirectionalIterator first, BidirectionalIterator last ); template <class BidirectionalIterator, class Compare> bool next_permutation (BidirectionalIterator first, BidirectionalIterator last, Compare comp); //eg: *************************************************************************************/ /************************************************************************************* std::prev_permutation 所有排序容器适用 algorithm -------------------------------------------------------------------------------------- template <class BidirectionalIterator> bool prev_permutation (BidirectionalIterator first, BidirectionalIterator last ); template <class BidirectionalIterator, class Compare> bool prev_permutation (BidirectionalIterator first, BidirectionalIterator last, Compare comp); //eg: *************************************************************************************/ int myints[3]; void init() { myints[0]=2; myints[1]=1; myints[2]=3; } void init2() { myints[0]=3; myints[1]=2; myints[2]=3; } int main() { // next_permutation init(); cout << "The 3! possible permutations with 3 elements:\n"; sort (myints,myints+3);//从小到大 do { cout << myints[0] << " " << myints[1] << " " << myints[2] << endl; } while ( next_permutation (myints,myints+3) ); // while(next_permutation(myints,myints+3)) // cout << myints[0] << " " << myints[1] << " " << myints[2] << endl; init(); cout << "The 3! possible permutations with 3 elements:\n"; sort (myints,myints+3); reverse (myints,myints+3);//从大到小 do { cout << myints[0] << " " << myints[1] << " " << myints[2] << endl; } while ( prev_permutation (myints,myints+3) ); cout<<"--------------------------------------------------------"<<endl; init2(); cout << "The 3! possible permutations with 3 elements:\n"; sort (myints,myints+3); do { cout << myints[0] << " " << myints[1] << " " << myints[2] << endl; } while ( next_permutation (myints,myints+3) ); init2(); cout << "The 3! possible permutations with 3 elements:\n"; sort (myints,myints+3); reverse (myints,myints+3);//从大到小 do { cout << myints[0] << " " << myints[1] << " " << myints[2] << endl; } while ( prev_permutation (myints,myints+3) ); return 0; }
0 0
- STL算法-排列算法
- C++ STL 排列算法
- STL算法排列
- STL的排列算法next_permutation
- STL next_permutation(全排列算法)
- stl中的全排列算法
- 全排列算法之STL实现
- STL全排列算法next_permutation和prev_permutation
- STL库全排列算法next_permutation
- 排列 STL
- 类似stl中排列算法的组合算法
- STL经典算法集锦<六>之排列(next_permutation/prev_permutation)
- 用STL的next_permutation算法实现全排列
- STL经典算法集锦之排列(next_permutation/prev_permutation
- 全排列递归算法与STL:next_permutation()函数
- STL 排序算法之全排列sort和next_permutation
- 全排列算法解析(视频+详解+代码+STL)
- STL 中的全排列
- 超级强大的vim配置(vimplus)
- activiti5.18 建表测试
- python服务器环境搭建(1)——本地服务器准备
- Windows驱动开发:3 WRK调试环境搭建
- 125. Valid Palindrome
- STL算法排列
- go设置
- 对异步IO的理解
- L1-019. 谁先倒
- How to hide credential providers from Login Screen for Windows 7
- Android 多级菜单联动操作
- DS18B20
- 解决 div或者a标签的高度比里面的img高度多了5px 问题
- ES6新特性概览