From 0484fe70dedd16c3b56b2ab63fe085b7535836a1 Mon Sep 17 00:00:00 2001 From: Jean-Loup Beaussart Date: Tue, 24 Feb 2015 10:45:33 +0100 Subject: [PATCH] =?UTF-8?q?Recherche=20s=C3=A9quentielle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- S2/TP4/tp4.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/S2/TP4/tp4.py b/S2/TP4/tp4.py index 130d610..9888a30 100644 --- a/S2/TP4/tp4.py +++ b/S2/TP4/tp4.py @@ -26,6 +26,23 @@ def squestion(lettre): question(1) # Programmer recherches seq, seq triée, dicho def seq(l, a, b, x): # Jean-loup + """ + Recherche séquentielle de l'élément x dans la liste l, entre les borne a et b, b étant exclu + list(x), int, int, x → (bool, int) + CU: 0 <= a < b <= len(l) + """ + + assert(a >=0 and b > a and b <= len(l)) + + i=a + + while i < b and l[i] != x: + i += 1 + if i < b: + return (True, i) + else: + return (False, 0) + return None def seqTrie(l, a, b, x): # Jean-loup