PyCharm进行断点式运行

代码:

def binary_search(li,val):
    left=0
    right=len(li)-1
    while left<=right: #候选区有值
        mid=(left+right)//2
        if li[mid]==val:
            return mid
        elif li[mid]>val:#待查找的值在mid的左边
            right=mid-1
        else:
            left=mid+1
    else:
        return None

li=[1,2,3,4,5,6,7,8,9]
print(binary_search(li,3))

image

image

image

一直按就可以啦

posted @ 2022-06-09 09:27  司砚章  阅读(85)  评论(0编辑  收藏  举报