Recent Changes - Search:

Oktatás

* Programozás 2
  + feladatsor
  + C feladatsor
  + Python feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

* Adator. prog.
  + feladatsor
  + quick link

Teaching

* Prog. for Data Sci. (TODO)

teaching assets


Félévek

* 2025/26/1
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

Lexicographically next permutation

See also https://dlang.org/phobos/std_algorithm_sorting.html#.nextPermutation

The lexicographic permutations of [0, 1, 2] are: 012, 021, 102, 120, 201, 210.

(1) next permutation
import std.stdio;
import std.algorithm;  // nextPermutation()

void main()
{
    int[] a = [0, 1, 2];

    do
    {
        writeln(a);
    }
    while (nextPermutation(a));

    writeln("---");
    a = [2, 1, 0];
    writeln(nextPermutation(a)); // false
    writeln(a); // [0, 1, 2]
}

Output:

[0, 1, 2]
[0, 2, 1]
[1, 0, 2]
[1, 2, 0]
[2, 0, 1]
[2, 1, 0]
---
false
[0, 1, 2]

Notes:

  • nextPermutation() modifies the list in-place. The list is changed to contain the lexicographically next permutation.
  • If the elements are in reverse order, i.e. lexicographically this is the last permutation, then it returns false; otherwise it returns true. When it returns false, it still modifies the list, so the list will contain the lexicographically first permutation.
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2025 August 21, 12:13