zoukankan      html  css  js  c++  java
  • Python-冒泡和快排

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

  • 相关阅读:
    c++ struct 使用
    c++数组、字符串操作
    c++ List、Vector、Stack、Queue使用
    十三、哈希表
    十二、234树
    十一、红黑树
    十、哈夫曼编码
    九、二叉树
    八、高级排序
    七、递归
  • 原文地址:https://www.cnblogs.com/pw20180101/p/8932386.html
Copyright © 2011-2022 走看看