用冒泡排序法,对10个整数按从小到大顺序进行排序,最后输出排序结果
时间: 2023-05-23 08:03:55 浏览: 49
C# 冒泡法排序可视化程序,用不同长度条形柱表示数值,条形柱移动,表示冒泡法的实现。
5星 · 资源好评率100%
Sure! Here is the code for bubble sort in Python:
numbers = [5, 2, 9, 1, 5, 6, 8, 3, 10, 4]
for i in range(len(numbers)):
for j in range(len(numbers) - 1):
if numbers[j] > numbers[j+1]:
temp = numbers[j]
numbers[j] = numbers[j+1]
numbers[j+1] = temp
print(numbers)
This will sort the list of numbers using bubble sort and print out the sorted result.
阅读全文