Python 冒泡排序
def bubble ( n, list ) :
for i in range ( 0 , len ( list ) - n- 1 ) :
temporary_variable= 0
if list [ i] > list [ i+ 1 ] :
temporary_variable= list [ i + 1 ]
list [ i + 1 ] = list [ i]
list [ i] = temporary_variable
n= n+ 1
if n!= len ( list ) - 1 :
bubble( n, list )
else :
return list
list = [ 9 , 4 , 7 , 1 , 100 , 54 , 76 , 12 , 74 , 52 , 82 , 92 , 99 , 23 , 15 ]
bubble( 0 , list )
print ( list )
Python 快速排序
def qulickly_sort ( list , left, right) :
def sort_mid ( list , left, right) :
temporary_variable = list [ left]
while ( right != left) :
while ( list [ right] >= temporary_variable) and right != left:
right -= 1
list [ left] = list [ right]
while ( list [ left] <= temporary_variable) and right != left:
left += 1
list [ right] = list [ left]
list [ left] = temporary_variable
return left
if left< right:
mid= sort_mid( list , left, right)
qulickly_sort( list , left, mid - 1 )
qulickly_sort( list , mid + 1 , right)
list = [ 9 , 4 , 7 , 1 , 100 , 54 , 76 , 12 , 74 , 52 , 82 , 92 , 99 , 23 , 15 ]
qulickly_sort( list , 0 , len ( list ) - 1 )
print ( list )