nextPermutation
fn
bool nextPermutation(alias less = "a < b", BidirectionalRange)(BidirectionalRange range) if (isBidirectionalRange!BidirectionalRange &&
hasSwappableElements!BidirectionalRange)- Permutes
rangein-place to the next lexicographically greater - permutation.
- The predicate
lessdefines the lexicographical ordering to be used on - the range.
- If the range is currently the lexicographically greatest permutation, it is
- permuted back to the least permutation and false is returned. Otherwise,
- true is returned. One can thus generate all permutations of a range by
- sorting it according to
less, which produces the lexicographically - least permutation, and then calling nextPermutation until it returns false.
- This is guaranteed to generate all distinct permutations of the range
- exactly once. If there are N elements in the range and all of them are
- unique, then N! permutations will be generated. Otherwise, if there are
- some duplicated elements, fewer permutations will be produced. ---- // Enumerate all permutations int[] a = 1,2,3,4,5; do { // use the current permutation and // proceed to the next permutation of the array. } while (nextPermutation(a)); ---- *
Parameters