mardi 28 juin 2016

Conversion from Python to C++ 11

i have written the following code in Python but i struggle with c++ 11 syntax. Could someone convert it for me and reply with the c++ version?

def BinarySearch(Sequence , Value):
    Found = False
    StartPos = 0
    EndPos = len(Sequence) - 1

    while (StartPos <= EndPos and not Found):
        MiddlePoint = (StartPos + EndPos) // 2

        if Value == Sequence[MiddlePoint]:
            Found = True

        else:
            if Value > Sequence[MiddlePoint]:
                StartPos = Sequence[MiddlePoint]
                #print ("I am more than the search value")

            else:
                EndPos = Sequence[MiddlePoint]
                #print ("I am less than the search value")

    if Found == True:
        print("Your search item: " + str(Value) + ", was found at position " + str(MiddlePoint + 1))
    else:
        print("Your search item: " + str(Value) + ", was not found in the given list")

Aucun commentaire:

Enregistrer un commentaire