标签:numbers ati you one def ant ber algorithm none
def permutationN(n): a=[None]*n for i in range(n): a[i]=i+1 sum=1 for j in range(n): sum*=(j+1) i=0 for k in range(sum): # If you want to use stack #a[i:i+2]=swapStack(a[i],a[i+1]) a[i:i+2]=[a[i+1],a[i]] print(a) i+=1 if i==(n-1): i=0
[Algorithm] A nonrecursive algorithm for enumerating all permutations of the numbers {1,2,...,n}
标签:numbers ati you one def ant ber algorithm none
原文地址:https://www.cnblogs.com/chiyeung/p/9686007.html