FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python/binarysearch.py at data-struct · YuckFu/python · GitHub
YuckFu
/
python
Public
forked from
flypythoncom/python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python
/
binarysearch.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
25 lines (23 loc) · 556 Bytes
Breadcrumbs
python
/
binarysearch.py
Copy path
File metadata and controls
25 lines (23 loc) · 556 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def
BinarySearch
(
l
,
key
):
low
=
0
high
=
len
(
l
)
-
1
i
=
0
while
(
low
<=
high
):
i
=
i
+
1
mid
=
low
+
((
high
-
low
)
>>
1
)
if
(
l
[
mid
]
<
key
):
low
=
mid
+
1
elif
(
l
[
mid
]
>
key
):
high
=
mid
-
1
else
:
print
"use %d times"
%
i
return
mid
return
-
1
if
__name__
==
"__main__"
:
l
=
[
1
,
4
,
5
,
6
,
7
,
8
,
9
,
44
,
333
,
2233
]
print
l
print
BinarySearch
(
l
,
4
)
print
BinarySearch
(
l
,
44
)
print
BinarySearch
(
l
,
8
)
print
BinarySearch
(
l
,
2233
)
print
BinarySearch
(
l
,
77
)
Back
|
FazBrowse Home
|
New Git URL