zoukankan      html  css  js  c++  java
  • python循环

    #for循环之二分查找
    def seek(targe=66,arr=[11,22,33,68],left=0,right=3):
        while left<right:
             mid=(left+right)//2
             i=arr[mid]
             if i==targe:
                 return mid+1
             elif i>targe:
                 right=mid-1
                 #seek(targe,arr,left,right)
             else:
                left=mid+1
                #seek(targe,arr,left,right)
        return -1
    #while循环合并2个有序的数组,这是归并排序的重点
    def sort(arr1,arr2):
        i,j,k=0,0,0
        arr3=[]
        while(i<len(arr1) and j<len(arr2)):
            if arr1[i]<arr2[j]:
                arr3.insert(k,arr1[i])
                i+=1
                k+=1
            else:
                arr3.insert(k,arr2[j])
                j+=1
                k+=1
    
        while i<len(arr1):
            arr3.insert(k,arr1[i])
            i+=1
            k+=1
        while j<len(arr2):
            arr3.insert(k,arr2[j])
            j=j+1
            k=k+1
        for  elem in arr3:
            print(elem,end=" ")
    
    arr1=[1,3,5,7]
    arr2=[2,4,6,8,78]
    sort(arr1,arr2)
  • 相关阅读:
    Java Concurrency
    Java Concurrency
    Java Concurrency
    Java Concurrency
    Java Concurrency
    Java Concurrency
    Java Concurrency
    Java Concurrency
    存储的瓶颈(2)
    存储的瓶颈(3)
  • 原文地址:https://www.cnblogs.com/yc-c/p/10398992.html
Copyright © 2011-2022 走看看