mirror of
https://github.com/Fare-spec/cours.git
synced 2025-12-09 19:30:40 +00:00
formatte file
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from sort_list import sort_list
|
||||
|
||||
def dichotomie(liste: list, element: any,bypass_sorting = False)->bool:
|
||||
|
||||
def dichotomie(liste: list, element: any, bypass_sorting=False) -> bool:
|
||||
"""This function return return True if element is in liste False else
|
||||
|
||||
Args:
|
||||
@@ -12,18 +13,20 @@ def dichotomie(liste: list, element: any,bypass_sorting = False)->bool:
|
||||
"""
|
||||
if liste == []:
|
||||
return False
|
||||
assert type(element) == type(liste[0]), "Wrong type between liste and element" # On estime que la liste contient un seul et unique type...
|
||||
assert type(element) == type(
|
||||
liste[0]
|
||||
), "Wrong type between liste and element" # On estime que la liste contient un seul et unique type...
|
||||
if bypass_sorting == False:
|
||||
liste = sort_list(liste)
|
||||
N, start, find,i = len(liste)-1, 0, False, 0
|
||||
N, start, find, i = len(liste) - 1, 0, False, 0
|
||||
end = N
|
||||
while (find != True) and (start <= end):
|
||||
middle = (start + end)//2
|
||||
middle = (start + end) // 2
|
||||
if liste[middle] == element:
|
||||
find = True
|
||||
|
||||
elif element > liste[middle]:
|
||||
start = middle+1
|
||||
start = middle + 1
|
||||
else:
|
||||
end = middle - 1
|
||||
return find
|
||||
|
||||
Reference in New Issue
Block a user