def arrange(pos_int):
#将1-N放入列表tempList中,已方便处理
tempList = [i+1 for i in range(pos_int)]
print(tempList)
while tempList != [pos_int-i for i in range(pos_int)]:
for i in range(pos_int-1,-1,-1):
if(tempList[i]>tempList[i-1]):
#考虑tempList[i-1]后面比它大的元素中最小的,交换。
minmax = min([k for k in tempList[i::] if k > tempList[i-1]])
#得到minmax在tempList中的位置
index = tempList.index(minmax)
#交换
temp = tempList[i-1]
tempList[i-1] = tempList[index]
tempList[index] = temp
#再交换tempList[i]和最后一个元素,得到tempList的下一个排列
temp = tempList[i]
tempList[i] = tempList[pos_int-1]
tempList[pos_int-1] = temp
print(tempList)
break
arrange(5)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有