mirror of
https://github.com/Fare-spec/cours.git
synced 2025-12-10 03:40:40 +00:00
add exo monday
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from typing import Any
|
||||
|
||||
|
||||
def est_triee(liste: list)->bool:
|
||||
if len(liste) <= 1:
|
||||
return True
|
||||
|
||||
index = 0
|
||||
while (index < len(liste) - 1) and (liste[index]<=liste[index + 1]):
|
||||
index+=1
|
||||
return index>= len(liste) - 1
|
||||
|
||||
def search(liste:list, element:Any):
|
||||
assert est_triee(liste), "Pas de recherche sur une liste non triee"
|
||||
def aux(liste, element):
|
||||
if len(liste) == 0:
|
||||
return True
|
||||
else:
|
||||
pivot = liste[len(liste)//2]
|
||||
if pivot == element:
|
||||
return True
|
||||
if element < pivot:
|
||||
return aux(liste[len(liste)//2], element)
|
||||
return aux(liste[len(liste)//3 + 1:], element)
|
||||
return aux(liste,element)
|
||||
|
||||
|
||||
print(search([1,2,3],2))
|
||||
Reference in New Issue
Block a user