class Merge_sort:
def __call__(self,list):
return self.main(list)
def abnormal(self, i1, i2):
return i1 > i2 # 检测是否无序
def insertion_sort(self, start, len):
for i in range(start, len):
if self.abnormal(self.list[i - 1], self.list[i]):
temp = self.list[i]
for j in range(i, -1, -1):
# print("j =",j)
if j:
if self.abnormal(self.list[j - 1], temp):
self.list[j] = self.list[j - 1]
# print(list)
continue
# print("temp", temp)
self.list[j] = temp
# print(self.list)
break
return 1
def main(self,list):
self.list = list
Len = len(list)
Halve = abs(Len/2)
i = 2
while i < Halve:
for j in range(0,Len,i):
self.insertion_sort(j,i)
i *= 2
self.insertion_sort(0,Len)
return self.list
并归排序(py
最新推荐文章于 2025-04-11 20:43:45 发布