lubh 发表于 2015-12-15 09:45:24

python 实现的几个排序-出自Data Structure and Algorithms with python


[*]#selection sort

[*]def select(seq,start):
[*]    minIndex=start
[*]    for j in range(start+1,len(seq)):
[*]      if seq[minIndex] > seq[j]:
[*]            minIndex=j
[*]    return minIndex
[*]
[*]
[*]def selSort(seq):
[*]    for i in range(len(seq)-1):
[*]      minIndex=select(seq,i)
[*]      seq[i],seq[minIndex]=seq[minIndex],seq[i]



#merge sort
def merge(seq,start,mid,stop):
    lst=[]
    i=start
    j=mid

    while i
页: [1]
查看完整版本: python 实现的几个排序-出自Data Structure and Algorithms with python