Python实现二分查找
来源:互联网 发布:网络教育有哪些学校 编辑:程序博客网 时间:2024/05/21 19:47
这么晚,没事干,写个程序练练手,最近在看Python,就拿Python开刀吧;上oschina看有人写了个二分查找的东西,看了下有问题,所以自己忍不住也拿出来写写;纯练手!!!
'fileName--BinarySearch.py'src = []def BinarySearch(low, high, target, *src): '二分查找' while low <= high: mid = (low + high) // 2 midVal = src[mid] if target < midVal: high = mid - 1 elif target > midVal: low = mid + 1 else: return mid BinarySearch(low, high, target, *src)print('Please input 10 number:')for number in range(10): src.append(int(input('Num %d:' % number)))sortList = tuple(src)key = int(input('Please input key:'))location = BinarySearch(0, len(src) - 1, key, *sortList)if location != None: print('Find target at %d' % (location + 1))else: print('No target!')
- Python实现二分查找
- Python实现二分查找
- python实现二分查找
- 二分查找 python实现
- python实现二分查找
- python实现二分查找
- Python实现二分查找
- python实现二分查找
- 用Python实现二分查找
- 用Python实现二分查找
- Python实现的二分查找
- Python实现二分查找法
- python的二分查找实现
- Python实现二分查找算法
- python实现的二分查找
- 二分查找及python实现
- 使用python实现二分查找
- 二分查找算法python实现
- 让SAE支持支付宝“确认发货”接口,完美解决"protocol error"
- 使用 dom4j 解析 XML
- (转载)android多线程及定时器处理方式
- 关于分页2
- 人生感悟
- Python实现二分查找
- 单例设计模式
- 在.NET/Mono上运行Java:Jeroens Frijters谈IKVM.NET
- 续:Mac狮子系统又暴安全隐患
- 输出1到1000,不使用循环
- hdoj 1242 宽度优先
- PHP session回收机制
- 分析stl function objects模块
- yii 中文书-agile_web_application_development_with_yii1.1_and_php5