惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
博客园_首页
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
博客园 - 司徒正美
有赞技术团队
有赞技术团队
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog

博客园 - 小默同学

C语言文件操作 makefile 文件的写法 tkinter教程 基本黑客技术 window下开机自启动.bat文件和后台启动.bat文件 django 用 uvicorn 部署 python 声音去噪处理 basis of PHP DBMA about mysql 免费文字转语音工具 c:\windows\temp\ccvjvr7w.o:problemfour.cpp:(.text+0x17): undefined reference to `std::basic_istream< - 小默同学 Android连接第三方模拟器 vscode下搭建springboot python jwt 一篇文章极速复习drf知识点 LCD1602代码记录 外部排序 {&quot;detail&quot;:[{&quot;loc&quot;:[&quot;body&quot;],&quot;msg&quot;:&quot;field required&quot;,&quot;type&quot;:&quot;value_error.missing&quot;}]} 防止win10系统把破解软件当成病毒自动删除keil的破解软件 ERROR 1366 (HY000): Incorrect string value: '\xC4\xE3\xBA\xC3' for column 'p - 小默同学
折半查找python代码实现
小默同学 · 2023-08-14 · via 博客园 - 小默同学
ls = [i+1 for i in range(11)]

i = 0

def binary_search(value, front, end):
    global i
    i += 1
    mid = (front + end)//2
    if end >= front:              # 这里是大于等于
        if value == ls[mid]:
            print(f"第{i}次查找成功:{ls[mid]}")
        elif value > ls[mid]:
            print(f"第{i}次查找元素:{ls[mid]}")
            front = mid + 1
            mid = (front + end) // 2
            binary_search(value, front, end)
        elif value < ls[mid]:
            print(f"第{i}次查找元素:{ls[mid]}")
            end = mid - 1
            mid = (front + end) // 2
            binary_search(value ,front, end)
    else:
        print("查找失败!")

binary_search(11, 0, len(ls)-1)