Trichotomie corrigée

This commit is contained in:
Jean-Loup Beaussart 2015-02-24 11:42:16 +01:00
parent c8f8de6a22
commit 26af6c5696

View file

@ -145,16 +145,14 @@ def tricho(l, a, b, x):
while d < f:
m1 = (d+f)//3
m2 = m1*2
if l[m1] < x:
if l[m1] >= x:
f = m1
elif l[m2] >= x:
d = m1+1
f = m2
elif l[m2] < x:
d = m2+1
else:
f = m1
d = m2+1
est_dedans = x == l[d]
return (est_dedans, d if x == l[d] else -1)
print(dicho(LEXIQUE, 0, len(LEXIQUE), 'banane'))
print(tricho(LEXIQUE, 0, len(LEXIQUE), 'banane'))
print(tricho(LEXIQUE_TRIE, 0, len(LEXIQUE_TRIE), 'banane'))