! # / usr / bin / Python # - * - Coding: UTF-. 8 - * - DEF Sort (Arr, newArr = []): IF len (Arr)> 0: lenNum = len (newArr); IF lenNum: # arr [0] than the current value of the first array of smaller IF newArr [0]> arr [0]: newArr.insert (0, arr [0]) #Arr [0] much better than the current value of the last bit of the array large elif newArr [-lenNum. 1] <Arr [0]: newArr.insert (lenNum, Arr [0]) # interposed between the else: for K, V in the enumerate (newArr): IF ((V <Arr [0]) & (newArr [K +. 1]> Arr [0])): newArr.insert (K +. 1, Arr [0]) BREAK the else: newArr.append (Arr [0]) del Arr [0] the Sort return (Arr, newArr) the else: return newArr arr = ['7','2','6','9','5','3','8','1','4'] print sort(arr)
python array sort (recursive)
Guess you like
Origin www.cnblogs.com/zhoupeng-php/p/11239584.html
Recommended
Ranking