BinäreSuche

mail@pastecode.io avatar
unknown
python
3 years ago
377 B
8
Indexable
def binaere_suche(elemente,wert):
    links = 0
    rechts = len(elemente)-1

    while links <= rechts:
        mitte = (links+rechts)//2
        
        if elemente[mitte]==wert:
            return elemente[mitte]
        elif elemente[mitte]<wert:
            links=mitte+1
        elif elemente[mitte]>wert:
            rechts=mitte-1
        else:
            return None