[Algorithm] A nonrecursive algorithm for enumerating all permutations of the numbers {1,2,...,n}
2021-06-20 23:05
标签:numbers ati you one def ant ber algorithm none [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.htmldef 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
上一篇:深入分析 Javac 编译原理
文章标题:[Algorithm] A nonrecursive algorithm for enumerating all permutations of the numbers {1,2,...,n}
文章链接:http://soscw.com/essay/96637.html