算法导论之python实现插入排序
生活随笔
收集整理的這篇文章主要介紹了
算法导论之python实现插入排序
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
插入排序的花費時間 c*n2,?c 是常數(shù)
偽代碼
INSERTION-SORT(A)
for i ?to A.length
key = A[j]
//Insert A[j] into the sorted sequence A[1... j-1]
i = j - 1
while i > 0 and A[i] > key
A[i+1] = A[i]
i ?=i - 1
A[i+1] = key
?
python3.4 :
def insertion_sort(sort_list):length = len(sort_list)
for i in range(length)[1:]:
key = sort_list[i]
j = i - 1
while j >= 0 and sort_list[j] > key:
sort_list[j+1] = sort_list[j]
j -= 1
sort_list[j+1] = key
轉載于:https://www.cnblogs.com/qianzhen/p/4251763.html
總結
以上是生活随笔為你收集整理的算法导论之python实现插入排序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android实例-手机安全卫士(十一)
- 下一篇: python下selenium测试报告整