Skip to content
Snippets Groups Projects
Commit f1d1c050 authored by Belkacemi Melissa's avatar Belkacemi Melissa
Browse files

indice_dicho

parent ef2630ec
No related branches found
No related tags found
No related merge requests found
......@@ -5,5 +5,5 @@
from minesweeper import Minesweeper
import graphicalboard
game = Minesweeper(20, 20, 10)
game = Minesweeper(20, 10, 1)
graphicalboard.create(game)
File mode changed from 100644 to 100755
......@@ -53,8 +53,14 @@ def indice_seq(elem: C, liste: list[C], comp: Callable[[C, C], int]) \
i=len(liste)
return(trouve,i)
def compare(x, y):
if x == y:
return 0
elif x < y:
return -1
else:
return 1
def indice_dicho(elem: C, liste: list[C], comp: Callable[[C, C], int]) \
-> tuple[bool, int]:
"""Renvoie un couple (trouve, i) tel que:
......@@ -82,7 +88,27 @@ def indice_dicho(elem: C, liste: list[C], comp: Callable[[C, C], int]) \
$$$ indice_dicho(42, [], compare)
(False, 0)
"""
...
if len(liste)!= 0:
d=0
f=len(liste)-1
while d<f :
m=(d+f)//2
if comp(elem,liste[m])>0:
d=m+1
else:
f=m
if comp(elem,liste[d])>0:
res=(comp(elem,liste[d])==0,d+1)
else:
res=(comp(elem,liste[d])==0,d)
else:
res=(False,0)
return res
def inserer(indice: int, elem: C, liste: list[C]) -> NoneType:
"""Insère l'élément elem à l'indice indice de la liste liste.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment