# Undestand when/why these are incorrect
# Compare with binarySearchIterative in lec27.py

def binarySearchIterativeA(L, x):
    global numIterations
    startIndex = 0
    endIndex = len(L)
    numIterations = 0
    while (startIndex < endIndex):
        numIterations = numIterations + 1
        midIndex = (startIndex+endIndex)//2
        print(midIndex, L[midIndex])
        if x == L[midIndex]:
            return(midIndex)
        elif x < L[midIndex]:
            endIndex = midIndex - 1
        else:
            startIndex = midIndex + 1
    return False

def binarySearchIterativeB(L, x):
    global numIterations
    startIndex = 0
    endIndex = len(L)
    numIterations = 0
    while (startIndex < endIndex):
        numIterations = numIterations + 1
        midIndex = (startIndex+endIndex)//2
        print(midIndex, L[midIndex])
        if x == L[midIndex]:
            return(midIndex)
        elif x < L[midIndex]:
            endIndex = midIndex
        else:
            startIndex = midIndex
    return False
