python实现常见数据结构与算法

#折半查找
def bs(array,goal,low,high):
    mid=(low+high)//2
    while low<=high:
        if goal==array[mid]:
            return mid
        elif goal>array[mid]:
            return bs(array,goal,mid+1,high)
        elif goal=index_list[mid][0]:
            low=mid+1
            mid=(high+low)//2
        elif goal=1:
            if array[k]1:
        for i in range(0,n,d):
            if i+d<=n:
                for j in range(i,i+d):
                        k=j
                        while k>=1:
                            if array[k]=1:
                            if array[k]=1:
            if array[k]high:
                    array[k]=array[k-1]
                    k-=1
                array[high+1]=tmp
            else:
                break
    return array
#冒泡排序
def bubble(array):
    for i in range(0,len(array)):
        exchange=False
        for j in range(len(array)-1,i,-1):
            if array[j]<=array[j-1]:
                array[j],array[j-1]=array[j-1],array[j]
                exchange=True
        if not exchange:
            return array
    return array
#快速排序(不会默写)
def part(array,start,end):
    mid=array[start]
    while start=mid and startlow:
        mid=part(array,low,high)
        quikSort(array,mid+1,high)
        quikSort(array,low,mid-1)
#简单选择排序
def simpleChoice(array):
    for i in range(0,len(array)):
        small=array[i]
        for j in range(i,len(array)):
            if array[j]

 

你可能感兴趣的:(基础知识)