Skip to content

Commit 42f02f1

Browse files
committed
二分查找算法实现
1 parent bc0728f commit 42f02f1

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

bin_search.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ list.index()无法应对大规模数据的查询,需要用其它方法解决
7474

7575
- 模块接受排序后的列表。
7676
- 本模块同样适用于长列表项。因为它就是用二分查找方法实现的,有兴趣可以看其源码(源码是一个很好的二分查找算法的例子,特别是很好地解决了边界条件极端的问题.)
77-
- 关于bisect模块的更多内容,可以参看官方文档
77+
- 关于bisect模块的更多内容,可以参看[官方文档](https://docs.python.org/2/library/bisect.html)
7878

7979
下面演示这个模块的一个函数
8080

bin_search.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ def bsearch(l, value):
7474
7575
- 本模块同样适用于长列表项。因为它就是用二分查找方法实现的,有兴趣可以看其源码(源码是一个很好的二分查找算法的例子,特别是很好地解决了边界条件极端的问题.)
7676
77+
-关于本模块,可以查看官方文档:https://docs.python.org/2/library/bisect.html
7778
"""
7879
#下面演示这个模块
7980

8081
from bisect import *
8182

8283
def bisectSearch(lst, x):
83-
i = bisect_left(lst, x)
84+
i = bisect_left(lst, x) #bisect_left(lst,x)得到x在已经排序的lst中的位置
8485
if i != len(lst) and lst[i] == x:
8586
return i
8687

0 commit comments

Comments
 (0)