Skip to content

Instantly share code, notes, and snippets.

@sosoyososo
Created September 18, 2013 15:18
Show Gist options
  • Save sosoyososo/6610716 to your computer and use it in GitHub Desktop.
Save sosoyososo/6610716 to your computer and use it in GitHub Desktop.
python:递归输出一个数组的全排列
def pickOne (array1, array2) :
length = len (array2)
if length == 0 :
return
for i in range (0, length) :
tempArray1 = array1[:]
tempArray2 = array2[:]
moveArrayItem (tempArray1, tempArray2, i)
print (tempArray1)
pickOne (tempArray1, tempArray2)
def moveArrayItem (array1, array2, index) :
if index < len(array2) :
array1.append (array2.pop(index))
array = [1,2,3,4,5,6]
tempArray = []
pickOne (tempArray, array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment