STL之 next_permutation
来源:互联网 发布:淘宝双十一晚会直播 编辑:程序博客网 时间:2024/05/22 15:22
next_permutation 函数可以用来处理全排列,例如给定一个三个int元素的数组 int arr[] ={4,1,2}; 求他们的所有排列方式
直接上代码
int arr[] ={4,1,2};sort(arr,arr+3);while(next_permutation(arr,arr+3)){for(int i=0;i<3;i++){cout<<arr[i]<<" ";}cout<<endl;}那么运行结果会是什么呢?
可以看到,除了 1 2 4 这个排列以外,其他的排列都已经打印出来了
而之所以没有打印 1 2 4 这个排列,是因为 sort函数排序后的序列正是 1 2 4,而next_permutation 返回的是当前序列的下一个序列
如果没有使用sort函数,打印结果会是什么呢?
答案是,程序只会打印 4 2 1
0 0
- STL之 next_permutation
- [POJ1833] 排列(STL之next_permutation)
- STL next_permutation
- 【STL】next_permutation
- [STL]next_permutation
- STL源码剖析之next_permutation,prev_permutation
- STL之next_permutation() 全排列函数
- STL之生成全排列:next_permutation & prev_permutation
- STL具体操作之next_permutation和prev_permutation函数
- STL之next_permutation和prev_permutation函数
- 【经典算法】STL之next_permutation和prev_permutation
- STL经典算法集锦<六>之排列(next_permutation/prev_permutation)
- STL经典算法集锦之排列(next_permutation/prev_permutation
- STL算法之 next_permutation、prev_permutation 的原理和实现
- C++ STL之next_permutation小证明与Java实现
- STL 排序算法之全排列sort和next_permutation
- STL之 next_permutation函数{(全排列)按字典序!!!!!}
- STL学习笔记之next_permutation(下一个排列)
- Leetcode: Remove Element
- 黑马程序员——对象方法与类方法
- python列表删除重复元素的三种方法
- 虚幻4——蓝图在脚本之间的交互
- 漫游Kafka设计篇之性能优化
- STL之 next_permutation
- palyframework学习日记一二三四
- 数组-12. 简易连连看(20)
- 漫游Kafka设计篇之Producer和Consumer
- Linux中Man Page的含义
- 黑马程序员一NSSet, NSDictionary
- NYOJ306 走迷宫(dfs+二分搜索)
- Codeforces Round #291 (Div. 2)E(DP+矩阵)
- 漫游Kafka设计篇之主从同步