% showBinarySearch
for k=1:10
clc
v = sort(ceil(100*rand(1,5)))
x= input('Search for...? ');
L = binarySearch(x, v);

% Check returned value L from binarySearch.
% L is the position AFTER WHICH to insert x if x is not found.
if L==0
fprintf('\n L=%d. Detail: %d < v(1).\n', L, x)
elseif L==length(v) && v(L)~=x
fprintf('\n L=%d. Detail: %d > v(%d) \n', L, x, length(v))
elseif L==length(v)
fprintf('\n L=%d. Detail: v(%d) <= %d \n', L, L, x)
else
fprintf('\n L=%d. Detail: v(%d) <= %d < v(%d) \n', L, L, x, L+1)
end

pause
end