mirror of
https://github.com/dlang/phobos.git
synced 2025-05-06 11:07:39 +03:00
Merge pull request #1822 from GassaFM/master
fix documentation for nextPermutation and nextEvenPermutation
This commit is contained in:
commit
97d3f75370
1 changed files with 12 additions and 9 deletions
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue