首页 > 编程语言 > 详细

[Algorithm] A nonrecursive algorithm for enumerating all permutations of the numbers {1,2,...,n}

时间:2018-09-21 14:24:50      阅读:138      评论:0      收藏:0      [点我收藏+]
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}

原文:https://www.cnblogs.com/chiyeung/p/9686007.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!