function dfs_stack ( n, first, adj_pointer, adj, label )

%*****************************************************************************80
%
%% DFS_STACK
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'DFS_STACK:\n' );
  fprintf ( 1, '  Depth-first search of a graph using a stack.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Step Visit:  Nodes we can visit next\n' );
  fprintf ( 1, '  ---- -----   -----------------------\n' );
  fprintf ( 1, '\n' );
%
%  Initialize.
%
  step = 0;
  visited(1:n) = 0;
  stack_num = 0;
  stack(1:n) = 0;

  while ( 1 )
%
%  What unvisited room shall we visit next?
%  (Take something off the stack.)
%
    while ( 1 )
      if ( step == 0 )
        room = first;
        break
      elseif ( stack_num == 0 )
        return
      else
        room = stack(stack_num);
        stack_num = stack_num - 1;
        if ( visited(room) == 0 )
          break;
        end
      end
    end
%
%  Visit the new room and look for unvisited neighbor rooms.
%  (Add things to the stack.)
%
    step = step + 1;
    visited(room) = step;

    for i = adj_pointer(room) : adj_pointer(room+1)-1
      room2 = adj(i);
      if ( visited(room2) == 0 )
        stack_num = stack_num + 1;
        stack(stack_num) = room2;
      end
    end
    fprintf ( 1, '    %2d     %c:  ', step, label(room) );
    for i = 1 : stack_num
      fprintf ( 1, '  %c', label ( stack(i) ) );
    end
    fprintf ( 1, '\n' );

  end

  return
end
