#冒泡排序函数defbubble_sort(lists):
count =len(lists);for k inrange(count):for j inrange(count-1):if lists[j]>lists[j+1]:
lists[j],lists[j+1]= lists[j+1],lists[j];print(lists);
lst =[];
size =int(input("Enter size of the list:\t"));for i inrange(size):
elements =int(input("Enter the element:\t"));
lst.append(elements);
bubble_sort(lst);
2、输出结果:
Enter size of the list: 5
Enter the element: 36
Enter the element: 45
Enter the element: 23
Enter the element: 11
Enter the element: 5
[5, 11, 23, 36, 45]
进程已结束,退出代码0
文章目录1、代码程序:2、输出结果:1、代码程序:#冒泡排序函数def bubble_sort(lists): count = len(lists); for k in range(count): for j in range(count-1): if lists[j]>lists[j+1]: lists[j],lists[j+1] = lists[j+1],lists[j]; print(lists