Skip to content

Commit

Permalink
Merge pull request #1822 from GassaFM/master
Browse files Browse the repository at this point in the history
fix documentation for nextPermutation and nextEvenPermutation
  • Loading branch information
monarchdodra committed Dec 29, 2013
2 parents 6c6c40f + 23d052a commit 97d3f75
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions std/algorithm.d
Expand Up @@ -11904,10 +11904,11 @@ unittest
----
// Enumerate all permutations
int[] a = [1,2,3,4,5];
while (nextPermutation(a))
do
{
// a now contains the next permutation of the array.
}
// use the current permutation and
// proceed to the next permutation of the array.
} while (nextPermutation(a));
----
* Returns: false if the range was lexicographically the greatest, in which
* case the range is reversed back to the lexicographically smallest
Expand Down Expand Up @@ -12114,10 +12115,11 @@ unittest
----
// Enumerate even permutations
int[] a = [1,2,3,4,5];
while (nextEvenPermutation(a))
do
{
// a now contains the next even permutation of the array.
}
// use the current permutation and
// proceed to the next even permutation of the array.
} while (nextEvenPermutation(a));
----
* One can also generate the $(I odd) permutations of a range by noting that
* permutations obey the rule that even + even = even, and odd + even = odd.
Expand All @@ -12132,11 +12134,12 @@ while (nextEvenPermutation(a))
// Enumerate odd permutations
int[] a = [1,2,3,4,5];
swap(a[$-2], a[$-1]); // a is now the first odd permutation of [1,2,3,4,5]
while (nextEvenPermutation(a))
do
{
// a now contains the next odd permutation of the original array
// use the current permutation and
// proceed to the next odd permutation of the original array
// (which is an even permutation of the first odd permutation).
}
} while (nextEvenPermutation(a));
----
*
* Warning: Since even permutations are only distinct from all permutations
Expand Down

0 comments on commit 97d3f75

Please sign in to comment.