zoukankan      html  css  js  c++  java
  • 快速排序

    def bb(a,low,high):
        if low<high:
            c=low#c是要找的位置
            d=a[high]
            for i in range(low,high):
                if a[i]<d:
                    a[c],a[i]=a[i],a[c]
                    c+=1
            a[c],a[high]=a[high],a[c]    
            bb(a,low,c-1)
            bb(a,c+1,high)
     
    
    a=[21,3,12,6,2,87,45,21,17]
    bb(a,0,8)
    a=[32,6,34,517,76,53,31,4,2,47,11,54,62,23,54,12,9,5]
    #a1=[4,57,76,78]
    def ff(lis,begi,end):                 
        if begi<0 or begi>=end:
            return    
        start_begi=begi
        start_end=end
        begi+=1
                    
        while begi<end:
            while begi<end and lis[begi]<=lis[start_begi]:
                begi+=1
        
            while begi<end and lis[end]>=lis[start_begi]:
                end-=1
            lis[begi],lis[end]=lis[end],lis[begi]
        
                            
                
        if lis[start_begi]<=lis[end]:
            a[start_begi],a[end-1]=a[end-1],a[start_begi]
            ff(lis,start_begi,end-2)
            ff(lis,end,start_end)
        else:
            a[start_begi],a[end]=a[end],a[start_begi]
            ff(lis,start_begi,end-1)
            ff(lis,end+1,start_end)
                
    print (a) 
    ff(a,0,len(a)-1)
    print (a)        
                
  • 相关阅读:
    Cyber Security
    Cyber Security
    Cyber Security
    Cyber Security
    Balanced Number HDU
    Round Numbers POJ
    Bomb HDU
    不要62 HDU
    Making the Grade POJ
    You Are the One HDU
  • 原文地址:https://www.cnblogs.com/saolv/p/9415330.html
Copyright © 2011-2022 走看看