so i'm working on a program that search a term by dichotomy. It makes an infinite loop and i don't know why but i know where ( in the elif/else ). So here is my code :
def RechercheDichotomique(liste,x):# Algo pour recherche dichotomique
DebutListe=0
FinListe=len(liste)
while (FinListe-DebutListe)>1:# On ne cherche que si la liste a au moins un terme dedans
ElementCentral=int(len(liste[DebutListe:FinListe])/2)# On prend l'element central de la liste
liste[DebutListe:FinListe]
if liste[ElementCentral]==x:# Si l'element central est x correspondent on renvoie True
return (True)
elif liste[ElementCentral]<x:# Si l'element central est inferieur a x alors on prend la moitie superieure
DebutListe=ElementCentral
FinListe=len(liste)
else:# Sinon on prend la partie inferieure de la liste
DebutListe=0
FinListe=int((FinListe)/2)
if FinListe-DebutListe==1 and liste[ElementCentral]==x:# On verifie qu'il ne reste qu'un terme dans la liste et que le seul qui reste est bien x
return (True)
I know there is plenty ways of doing it more easily but i need to keep the List untouched. Thanks you already guys!