Created
September 18, 2013 15:18
-
-
Save sosoyososo/6610716 to your computer and use it in GitHub Desktop.
python:递归输出一个数组的全排列
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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