Home > Backend Development > Python Tutorial > python bubble sort

python bubble sort

大家讲道理
Release: 2016-11-09 10:48:06
Original
1152 people have browsed it

[Python]代码   

def maopao(list):
    for i in range(0, len(list)):
        for j in range(len(list) - 1, i - 1, -1):
            if list[j] < list[j-1]:
                temp = list[j]
                list[j] = list[j-1]
                list[j-1] = temp
            #printResult(list)
 
def printResult(list):
    for i in range(0, len(list)):
        print list[i],
    print
         
List = [9,1,7,3,8,2,6,4,0]
maopao(List)
print List
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template