function [ AP, AL ] = graph_adj_to_adj_list ( A )

%*****************************************************************************80
%
%% graph_adj_to_adj_list() converts an adjacency matrix to an adjacency list.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    27 April 2026
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer A(node_num,node_num), the adjacency matrix.
%
%  Output:
%
%    integer AP(node_num+1): the index of the first edge for each node.
%
%    integer AL(edge_num): the list of ending nodes for each edge.
%
  node_num = size ( A, 1 );
  edge_num = sum ( sum ( A ) );

  AP = zeros ( node_num + 1, 1 );
  AL = zeros ( edge_num, 1 );

  k = 1;
  AP(1) = 1;
  for node_i = 1 : node_num
    for node_j = 1 : node_num
      if ( A(node_i,node_j) ~= 0 )
        AL(k) = node_j;
        k = k + 1;
      end
    end
    AP(node_i+1) = k;
  end

  return
end

