function values = quickSort2(values, startIndex, endIndex)
%disp(values(startIndex:endIndex));

if (startIndex < endIndex)
    pivot = values(endIndex);
    left = startIndex;
    right = endIndex;
    while(left < right)
        if (values(right-1) >= pivot)
            values(right) = values(right - 1);
            right = right - 1;
        elseif (values(left) >= pivot)
            values(right) = values(left);
            values(left) = values(right - 1);
            right = right - 1;
            left = left + 1;
        else
            left = left + 1;
        end
    end
    values(right) = pivot;
    %disp(values);
    if (endIndex - startIndex > 1)
        values = quickSort2(values, startIndex, right-1);
        values = quickSort2(values, right+1, endIndex);
    end
end
