%
% add2sortedlist.m
%
% function to take a given array, and add a given number to it,
% in sorted order.
%
% a = add2sortedlist([1, 7, 10], 5);
% a would then become [1, 5, 7, 10]
%
%assuming array is sorted
function ar= add2sortedlist(inputarray, inputnum)

ar = [];

counter=1;
while(counter<= length(inputarray))
    if (inputarray(counter) < inputnum)
         location = 'after';
         n = counter;
    else
         location = 'before';
    end
    s = sprintf('At index %d is %d %s', counter,inputarray(counter), ...
        location);
    disp(s)
    counter = counter + 1;
    
end
% disp(n);
ar = [inputarray(1:n), inputnum, inputarray(n+1:length(inputarray))];

