function x = insertSortInplace(x)
% Sort vector x in ascending order using Insertion sort

n = length(x);
for i= 1:n-1
% Sort x(1:i+1) given that x(1:i) is sorted
j= i;
need2swap= x(j+1) < x(j);
while need2swap
temp= x(j);
x(j)= x(j+1);
x(j+1)= temp;
j= j-1;
need2swap= j>0 && x(j+1)<x(j);
end
end