function A = i4row_sort_rotate_ascending ( A )
%*****************************************************************************80
%
%% i4row_sort_rotate_ascending() uses rotation to ascending sort rows of A.
%
% Discussion:
%
% An I4ROW is an MxN array of integers, regarded as M instances of
% an N-element row vector.
%
% If A is an I4ROW, then to ascending sort the rows of A, we
% consider each row I from 1 to M, and seek the "rotation" of this
% row that results in the row that is lexically smallest.
%
% A rotation of a row vector R1 of length N uses an index K between
% 1 and N, and produces the row vector
% R2 = [ R(1:K-1), R(K:N) ].
%
% Vector R1 is lexically less than vector R2 if:
%
% R1 < R2 <=> R1(1) < R2(1) or
% ( R1(1:1) == R2(1:1) and R1(2) < R2(2) ) or
% ...
% ( R1(1:N-1) == R2(1:N-1) and R1(N) < R2(N) ).
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 21 February 2021
%
% Author:
%
% John Burkardt
%
% Input:
%
% integer A(M,N), the matrix whose rows are to be ascending sorted
% by rotation.
%
% Output:
%
% integer A(M,N), the matrix after ascending rotation sort.
%
[ Ar, Ac ] = size ( A );
for i = 1 : Ar
rmin = A(i,1:Ac);
for j = 2 : Ac
r = [ A(i,j:Ac), A(i,1:j-1) ];
if ( i4vec_lt ( r, rmin ) )
rmin = r;
end
end
A(i,:) = rmin;
end
return
end