Systematically generates permutations.
The class is very easy to use. Suppose that you wish to generate all
permutations of the strings "a", "b", "c", and "d". Put them into an array.
Keep calling the permutation generator's getNext () method until there are no
more permutations left. The getNext () method returns an array of integers,
which tell you the order in which to arrange your original array of strings.
See
main(java.lang.String[]) for an example.
One caveat. Don't use this class on large sets. Recall that the number of
permutations of a set containing n elements is n factorial, which is a very
large number even when n is as small as 20. 20! is 2,432,902,008,176,640,000.
The algorithm is from Kenneth H. Rosen, "Discrete Mathematics and Its
Applications", 2nd edition (NT:McGraw-Hill, 1991), pp. 282-284.
This source code is free for you to use in whatever way you wish.