1 import numpy as np 冒泡 1 2 3 4 5 6 7 8 9 10 def bubble_sort(data): for i in range(len(data)): x = 0 for j in range(len(data)-i-1): print(data) if data[j] > data[j+1]: x = 1 data[j] ,data[j+1] = data[j+1],data[j] if not x: break 1 2 3 4 sample = np.random.randint(10,size = 10) print(sample) print('--------') bubble_sort(sample) 1 2 3 4 5 6 7 8 9 10 11 12