Jump to content

Permutations: Difference between revisions

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":
<lang c>
//Author Ivan Gavryushin @dcc0
#include <stdio.h>
#include <string.h>
Line 1,137 ⟶ 1,138:
}
</lang>
 
=={{header|C}}==
See [[wp:Permutation#Systematic_generation_of_all_permutations|lexicographic generation]] of permutations.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.