class Insert:
def __init__(self):
super(Insert, self).__init__()
@staticmethod
def sort(a):
for i in range(1, len(a)):
for j in range(i-1, -1, -1):
if Insert.compare(a, j, i):
Insert.exchange(a, j, i)
i = j
@staticmethod
def compare(a, i, j):
if a[i] >= a[j]:
return True
return False
@staticmethod
def exchange(a, i, j):
temp = a[i]
a[i] = a[j]
a[j] = temp
if __name__ == '__main__':
insert = Insert()
t = [1, 3, 2, 4, 0, 6, 5, 7, 123, 1, 25, 3, 123, 5, 5, 2, 3, 5, 9, 12, 34, 231, 32, 12, 23]
insert.sort(t)
print(t)
转载请注明原文地址:https://blackberry.8miu.com/read-31740.html