def iterative_partition(data, left, right):
    """
    Function which partitions the data into two segments,
    the left which is less than the pivot and the right
    which is greater than the pivot. The pivot for this
    algo is the right most index. This function returns
    the ending index of the pivot.

    :param data: array to be sorted
    :param left: left most portion of array to look at
    :param right: right most portion of the array to look at
    """
    x = data[right]
    i = left - 1
    j = left
    while j < right:
        if data[j] <= x:
            i = i + 1
            data[i], data[j] = data[j], data[i]
        j = j+1
    data[i + 1], data[right] = data[right], data[i + 1]
    return i + 1