1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| arr = eval(input("请输入需要排序的值,以中文逗号分隔:"))
l = len(arr)
def Bubble(arr: list, l: int): for i in range(l): for j in range(0, l-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j]
def ChangeArrTypeToList(arr): int_arr = [] for i in arr: int_arr.append(int(i)) return int_arr
arr = ChangeArrTypeToList(arr)
Bubble(arr, l) print("排序后的顺序:") for i in range(l): print("%d" % arr[i])
|