算法复习-全排列的非递归和递归实现(含重复元素)
from http://blog.csdn.net/so_geili/article/details/71078945
- Find the largest index
ksuch thatnums[k] < nums[k + 1]. If no such index exists, the permutation is sorted in descending order, just reverse it to ascending order and we are done. For example, the next permutation of[3, 2, 1]is[1, 2, 3]. - Find the largest index
lgreater thanksuch thatnums[k] < nums[l]. - Swap the value of
nums[k]with that ofnums[l]. - Reverse the sequence from
nums[k + 1]up to and including the final elementnums[nums.size() - 1].
浙公网安备 33010602011771号