Stepping through all permutations one swap at a time

前端 未结 4 1724
你的背包
你的背包 2020-12-10 05:19

Given a list of n distinct items, how can I step through each permutation of the items swapping just one pair of values at a time? (I assume it is possible, it certainly fee

4条回答
  •  青春惊慌失措
    2020-12-10 05:47

    You could have a look at https://sourceforge.net/projects/swappermutation/ which is a Java implementation of exactly you requirements: an Iterator that generates Swaps. Created this some time ago an recently updated.

提交回复
热议问题