Java Code for permutations of a list of numbers

后端 未结 4 1405
臣服心动
臣服心动 2020-12-15 11:24

I have written a program to find all the possible permutations of a given list of items. This precisely means that my program prints all possible P(n,r) values for r=0 to n<

4条回答
  •  爱一瞬间的悲伤
    2020-12-15 12:13

    If you're not storing it -- if you're just iterating through it -- then consider using Heap's algorithm (#3 on http://www.cut-the-knot.org/do_you_know/AllPerm.shtml) -- or, just to make your life easier, use Guava's Collections2.permutations, which doesn't actually construct the whole list of permutations -- it walks through them on the fly. (Disclosure: I contribute to Guava.)

提交回复
热议问题