Python案例 005 (三位数字排序)



# -*- 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


posted @ 2017-07-17 22:05  yuerspring  阅读(253)  评论(0编辑  收藏  举报