Recherche séquentielle
This commit is contained in:
parent
d56c275475
commit
0484fe70de
|
@ -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
|
||||
|
|
Reference in a new issue