pablouche
pablouche

Reputation: 7291

How do I generate all permutations of a list of numbers?

How do I generate all possible permutations of a list of numbers in C?

As an example, [1, 8, 12] would generate

[1, 12, 8],
[12, 8, 1],
[12, 1, 8], ...

Upvotes: 3

Views: 5628

Answers (1)

Vishal
Vishal

Reputation: 12379

Have a look at this Johnson-Trotter Algorithm and applet it is exactly what you want.

Upvotes: 2

Related Questions