From 26af6c5696e1e31e4c6f424c9b667976748bd8a0 Mon Sep 17 00:00:00 2001 From: Jean-Loup Beaussart Date: Tue, 24 Feb 2015 11:42:16 +0100 Subject: [PATCH] =?UTF-8?q?Trichotomie=20corrig=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- S2/TP4/tp4.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/S2/TP4/tp4.py b/S2/TP4/tp4.py index 94bd870..e349a02 100644 --- a/S2/TP4/tp4.py +++ b/S2/TP4/tp4.py @@ -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')) \ No newline at end of file +print(tricho(LEXIQUE_TRIE, 0, len(LEXIQUE_TRIE), 'banane')) \ No newline at end of file