1.Maximum of array
说明:给定一组数组,进行排序,得到最大值和最小值。
1 input data: 2 1 3 5 7 9 11 ... 295 297 299 300 298 296 ... 12 10 8 6 4 2 3 4 answer: 5 300 1
利用插入排序算法进行排序:
1 Array = [27871, -16173, -31511, -13095, 30159, -55191, -15285, 14394, 69666, -17640, -20828, 45000] 2 3 for j in range(1, len(Array)): 4 key = Array[j] 5 i = j - 1 6 while i >=0 and Array[i] > key: 7 Array[i+1] = Array[i] 8 i = i - 1 9 Array[i+1] = key 10 11 print(Array[len(Array)-1], end=‘ ‘) 12 print(Array[0], end=‘ ‘) #输出:69666 -55191
时间: 2024-10-12 16:30:50