# -*- coding:utf-8 -*-
"""
enter 3 unit ,and sort them
"""
L = []
for x in range(3):
L.append(int(raw_input("enter one unit data:\n")))
L.sort()
L.sort(reverse=True)
print L
# try with bubble sort
bubbleList = [12,123,45,78,43,21,99,78,45,34,22,26]
bubbleLen = len(bubbleList)
for i in range(1 ,bubbleLen):
for j in range(1,bubbleLen - i+1):
if bubbleList[j-1] > bubbleList[j] :
bubbleList[j - 1] , bubbleList[j] =bubbleList[j] , bubbleList[j-1]
print bubbleList
print bubbleList
本文通过Python代码演示了如何输入三个单位数据并使用sort方法进行排序,同时给出了冒泡排序的实现方式,帮助读者理解基本排序算法的工作原理。
1991

被折叠的 条评论
为什么被折叠?



