Permutations: Difference between revisions
Content added Content deleted
Line 1,048: | Line 1,048: | ||
Full non-recursive algorithm generating permutation in reversed lexicographical order. Taken from here: [https://habrahabr.ru/post/310574/]. It's a little bit modified algorythm of Narayana Pandit [3]. It reveres a string and works until a and b are not equal. It searches a new permutation directly (first internal cycle) as we do it on a sheet of paper. You can use English alphabet instead of digits. Run it from console with a parametr like "program.o 12345" or "program.o abcd": |
Full non-recursive algorithm generating permutation in reversed lexicographical order. Taken from here: [https://habrahabr.ru/post/310574/]. It's a little bit modified algorythm of Narayana Pandit [3]. It reveres a string and works until a and b are not equal. It searches a new permutation directly (first internal cycle) as we do it on a sheet of paper. You can use English alphabet instead of digits. Run it from console with a parametr like "program.o 12345" or "program.o abcd": |
||
<lang c> |
<lang c> |
||
//Author Ivan Gavryushin @dcc0 |
|||
#include <stdio.h> |
#include <stdio.h> |
||
#include <string.h> |
#include <string.h> |
||
Line 1,137: | Line 1,138: | ||
} |
} |
||
</lang> |
</lang> |
||
=={{header|C}}== |
=={{header|C}}== |
||
See [[wp:Permutation#Systematic_generation_of_all_permutations|lexicographic generation]] of permutations. |
See [[wp:Permutation#Systematic_generation_of_all_permutations|lexicographic generation]] of permutations. |