标签:style blog http color os ar for art div
快排,取一个key值,一般取第一个即可,将小于key的放到左边,大于key的放到右边,递归实现
1 import random 2 def quicksort(data, low = 0, high = None): 3 if high == None: 4 high = len(data) - 1 5 if low < high: 6 s, i, j = data[low], low, high 7 while i < j: 8 while i < j and data[j] >= s: 9 j = j - 1 10 if i < j: 11 data[i] = data[j] 12 i = i + 1 13 while i < j and data[i] <= s: 14 i = i + 1 15 if i < j: 16 data[j] = data[i] 17 j = j - 1 18 data[i] = s 19 quicksort(data, low, i - 1) 20 quicksort(data, i + 1, high) 21 22 data=[random.randint(1,100) for i in range(100)] 23 print(data) 24 quicksort(data) 25 print(data)
标签:style blog http color os ar for art div
原文地址:http://www.cnblogs.com/wizardjk/p/3953289.html