import random
import pretty_errors
def shellSort(data):
length = len(data)
while length > 1:
length = length/2
length = int(length)
for i in range(length):
for j in range(i, len(data), length):
current_data = j
for k in range(j-length, -1, -length):
if data[k] > data[current_data]:
data[k], data[current_data] = data[current_data], data[k]
current_data = k
else:
break
#打印输出
def printf(data_p, state):
for i in state:
print(i, end = '')
print(":")
for i in data_p:
print(i, end = ' ')
print('\n')
def main():
data = []
for i in range(30):
data.append(random.randint(-1000, 1000))
printf(data, "raw data")
shellSort(data)
printf(data, "sorted data")
if __name__ == '__main__':
main()