7 * permutation - Generate permutations
9 * This module allows you to generate all permutations of a given
10 * number of elements. It can also modify a user-supplied array in
11 * place through all those permutations.
13 * It uses the "plain changes" method, aka the
14 * Steinhaus-Johnson-Trotter algorithm to generate the permtations.
15 * This has some advantages over a naive recursive algorithm:
17 * - Each permutation is generated from the last by a single swap of
20 * - Constructing each permutation in place from the last takes
21 * amortized O(1) time.
23 * License: LGPL (v2.1 or any later version)
25 * // Given "1 2 3" outputs 1 2 3 1 3 2 3 1 2 3 2 1 2 3 1 2 1 3
27 * #include <ccan/permutation/permutation.h>
29 * int main(int argc, char *argv[])
32 * struct permutation *pi = permutation_new(argc - 1);
35 * for (i = 1; i < argc; i++)
36 * printf("%s ", argv[i]);
38 * } while (permutation_change_array(pi,
39 * &argv[1], sizeof(argv[1])));
43 int main(int argc, char *argv[])
45 /* Expect exactly one argument */
49 if (strcmp(argv[1], "depends") == 0) {
50 printf("ccan/build_assert\n");
55 if (strcmp(argv[1], "testdepends") == 0) {
56 printf("ccan/array_size\n");