function perm_to_cycle_test ( )

%*****************************************************************************80
%
%% PERM_TO_CYCLE_TEST tests PERM_TO_CYCLE.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    27 November 2015
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'PERM_TO_CYCLE_TEST\n' );
  fprintf ( 1, '  PERM_TO_CYCLE converts a permutation from\n' );
  fprintf ( 1, '  array to cycle form.\n' );

  n = 7;
  p = [ 4, 5, 1, 2, 3, 6, 7 ];
  perm_print ( n, p, '  Permutation:' );

  [ ncycle, t, index ] = perm_to_cycle ( n, p );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Corresponding cycle form:\n' );
  fprintf ( 1, '  Number of cycles is %d\n', ncycle );
  fprintf ( 1, '\n' );
  jlo = 0;
  for i = 1 : ncycle
    fprintf ( 1, '    ' );
    for j = jlo+1 : jlo+index(i)
      fprintf ( 1, '%4d', t(j) );
    end
    fprintf ( 1, '\n' );
    jlo = jlo + index(i);
  end

  return
end
