function backtrack_test ( )

%*****************************************************************************80
%
%% backtrack_test() tests backtrack().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 December 2015
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, ' \n' );
  fprintf ( 1, 'backtrack_test():\n' );
  fprintf ( 1, '  backtrack() supervises a backtrack search.\n' );
  fprintf ( 1, '  We demonstrate by searching for a nonattacking arrangement\n' );
  fprintf ( 1, '  of queens on a chessboard.\n' );
  fprintf ( 1, '\n' );

  n = 8;
  iarray = [];
  indx = 0;
  k = -1;
  nstack = -1;
  maxstack = n * n;
  stack = zeros ( maxstack, 1 );

  while ( true )

    [ n, iarray, indx, k, nstack, stack ] = backtrack ( n, iarray, ...
      indx, k, nstack, stack, maxstack );

    if ( indx == 1 )

      for i = 1 : n
        fprintf ( 1, '%4d', iarray(i) );
      end
      fprintf ( 1, '\n' );

    elseif ( indx == 2 )

      [ nstack, stack ] = queens ( n, iarray, k, nstack, stack, maxstack );

    else

      break

    end

  end

  return
end
