def partition(a, i, j): k = -1 while True: while k * (a[i] - a[j]) >= 0: if i == j: return i j += k a[i], a[j] = a[j], a[i] i, j, k = j, i - k, -k def qsort(a, i, j): if i < j: k = partition(a, i, j) qsort(a, i, k - 1) qsort(a, k + 1, j) def quickSort(a): qsort(a, 0, len(a) - 1) if __name__ == ‘__main__‘: from random import shuffle data = range(100) shuffle(data) print ‘before:\n‘, data quickSort(data) print ‘after:\n‘, data
刘硕老师Python精品课程:
《Python高级编程技巧实战》:
http://coding.imooc.com/class/62.html
《Python算法实战视频课程》:
http://study.163.com/course/courseMain.htm?courseId=1003617013
《Python科学计算—NumPy实战课程》:
http://edu.51cto.com/course/course_id-5046.html
熊猫TV直播间:
时间: 2024-12-13 16:37:12