function ksub_next2_test ( )

%*****************************************************************************80
%
%% ksub_next2_test() tests ksub_next2().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 May 2018
%
%  Author:
%
%    John Burkardt
%
  k = 3;
  n = 5;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'ksub_next2_test():\n' );
  fprintf ( 1, '  ksub_next2() generates the next K subset of an\n' );
  fprintf ( 1, '  N set by the revolving door method.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'Rank  Subset  Added  Removed\n' );
  fprintf ( 1, '\n' );
%
%  KSUB_NEXT2 does not have a good way of stopping.  
%  We will save the starting subset, and stop when the
%  new subset is the same as the starting one.
%
  in = 0;
  out = 0;
  rank = 0;
 
  a = ( 1 : k )';
 
  while ( true )
 
    rank = rank + 1;
    fprintf ( 1, '  %2d  ', rank );
    for i = 1 : k
      fprintf ( 1, '  %2d', a(i) );
    end
    fprintf ( 1, '    %2d', in );
    fprintf ( 1, '  %2d\n', out );
 
    [ a, in, out ] = ksub_next2 ( n, k, a );
 
    more = false;

    for i = 1 : k
      if ( a(i) ~= i )
        more = true;
      end
    end

    if ( ~ more )
      break
    end

  end
 
  return
end
