全排列算法实现
def ascii_permutation(arr:list): length = len(arr) while(True): print(arr) for i in range(length-1,-1, -1): if arr[i-1] < arr[i]: x = i-1 break if i == 0: return for j in range(length-1, x, -1): if arr[j] > arr[x]: y = j break arr[x], arr[y] = arr[y], arr[x] sub = arr[x+1:] sub.reverse() arr = arr[0:x+1] + sub def recursive_permutation(arr:list, start:int, end:int): if start == end: print(arr) else: for i in range(start, end): arr[i], arr[start] = arr[start], arr[i] recursive_permutation(arr, start+1, end) arr[i], arr[start] = arr[start], arr[i] #arr = [1,2,3,4] #ascii_permutation(arr) #print('****************') #recursive_permutation(arr,0,len(arr))