function [key index] =findmin(A)  % mind of A
  n=length(A);
  index=1;
  key=A(1);
  for j= 2:n
     if A(j) < key   % Update if and only if
       index=j;      % value encountered (i.e. A(j)) is smaller
       key  =A(j);   % than current value stored in key
     end
  end
end
