Python - bubbling and quicksort

#encoding=utf-8

def maopao(sec):
    for i in range(len(sec)):
        for j in range(i,len(sec)):
            if sec[i]>=sec[j]:
                sec[i],sec[j]=sec[j],sec[i]
    print sec

maopao([2,3,4,1,2,5,6,3,4,8]) 

 

 

 

#encoding=utf-8

def QuickSort(L, low, high):
    i = low
    j = high
    if i >= j:
        return L
    key = L[i]
    while i < j:
        while i < j and L[j] >= key:
            j = j-1                                                             
        L[i],L[j] = L[j],L[i]
        while i < j and L[i] <= key:    
            i = i+1
        L[j],L[i] = L[i],L[j]
    L[i] = key
    QuickSort(L, low, i-1)
    QuickSort(L, j+1, high)
    return L

print QuickSort([3,3,4,5,1,2,3,4,5,2],0,9)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324776029&siteId=291194637