Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
/pythonPublic archive

Update binary_search.py#129

Open
SOUMEE2000 wants to merge1 commit intoAllAlgorithms:master
base:master
Choose a base branch
Loading
fromSOUMEE2000:patch-1
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletionsalgorithms/sorting/binary_search.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,10 +25,11 @@ def binary_search(value, list_to_search):
search_value = -1
max_index = len(list_to_search) - 1
min_index = 0
middle_index = int(math.floor( (max_index + min_index) / 2))
current_element = list_to_search[middle_index]


while max_index >= min_index:

middle_index = int(math.floor( (min_index + max_index) / 2))
current_element = list_to_search[middle_index]

if current_element == value:
return current_element
Expand All@@ -38,10 +39,7 @@ def binary_search(value, list_to_search):

elif value < current_element:
max_index = middle_index - 1

middle_index = int(math.floor( (min_index + max_index) / 2))
current_element = list_to_search[middle_index]


return search_value


Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp