function backtrack_test ( )

%*****************************************************************************80
%
%% BACKTRACK_TEST tests BACKTRACK.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL 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 ( 1 )

    [ 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
