Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson16-diy2
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
67d6c7fa
authored
Jan 15, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
b213652d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
my_search.py
my_search.py
View file @
67d6c7fa
import
random
alist
=
range
(
1
,
101
)
alist
=
[
1
,
54
,
18
,
3
,
15
,
84
,
9
,
108
]
num
=
random
.
choice
(
alist
)
# 请完善二分查找函数binary_search(),查找出num在列表alist里面的索引位置
def
search
(
num
,
_list
):
def
search
(
num
,
_list_
):
for
i
in
range
(
0
,
len
(
_list_
)):
for
j
in
range
(
0
,
len
(
_list_
)
-
i
-
1
):
if
_list_
[
j
]
>
_list_
[
j
+
1
]:
_list_
[
j
],
_list_
[
j
+
1
]
=
_list_
[
j
+
1
],
_list_
[
j
]
_list
=
_list_
print
(
_list
)
low
=
0
high
=
len
(
_list
)
-
1
while
True
:
...
...
@@ -19,4 +25,4 @@ def search(num,_list):
if
not
num
in
_list
:
return
False
a
=
search
(
num
,
alist
)
print
(
a
,
num
-
1
)
\ No newline at end of file
print
(
a
,
num
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment