栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python 学习笔记(一)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python 学习笔记(一)

def Test1():
    print ("begin !")
    list = [10,9,8,7,6,5,4,3,2,1]
    QuickSort(list,0,9)
    for l in list:        
        print (str(l))
    return

def QuickSort(sortList,beginIndex,endIndex):
    PrintList(sortList,beginIndex,endIndex)
    if( endIndex-beginIndex + 1 == 2): #刚好要排序的只有两个
        ExchangeElementInList(sortList,beginIndex,endIndex)
    elif(endIndex-beginIndex + 1 <= 1):
        Donothing()
    else:
        result = HandleList(sortList,beginIndex,endIndex)
        QuickSort(sortList,result[0],result[1])
        QuickSort(sortList,result[2],result[3])
    return


def Donothing():
    
    return
def ExchangeElementInList(list,elIndex1,elIndex2):
    if list[elIndex2] >= list[elIndex1] :
        return
    else :
        temp = list[elIndex1]
        list[elIndex1] = list[elIndex2]
        list[elIndex2] = temp
        return
def HandleList(list,elIndex1,elIndex2):
    newList1 = []
    newList2 = []
    result = [] #0:left begin 1:left end  2:right begin 3:right end

    baseNum = list[elIndex1]
    for index in range(elIndex2-elIndex1):
        id = index+elIndex1+1
        if list[id] >= baseNum :
            newList2.append(list[id])
        else :
            newList1.append(list[id])

    index = elIndex1
    for id in range(len(newList1)):
        list[index] = newList1[id]
        index = index+1

    result.append(elIndex1)
    result.append(index-1)

    list[index] = baseNum
    index=index+1

    result.append(index)
    result.append(elIndex2)

    for id in range(len(newList2)):
        list[index] = newList2[id]
        index = index+1

    return result

def PrintList(list,startIndex,endIndex):
    return
    index = startIndex
    print("------- print array from "+str(startIndex)+" to "+str(endIndex)+" -------")
    while index<= endIndex :
        print(list[index])
        index = index+1
    print("------- end -------------")


#run
Test1()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/769754.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号