function [ AP, AL ] = graph_arc_to_adj_list ( L )

%*****************************************************************************80
%
%% graph_arc_to_adj_list() converts an arc list to an adjacency list.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    28 April 2026
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer L(edge_num,2): the arc list.
%
%  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.
%
  edge_num = size ( L, 1 );
  node_num = max ( max ( L ) );
%
%  Sort the information in L.
%
  L = sortrows ( L );
%
%  Allocate arrays.
%
  AP = zeros ( node_num + 1, 1 );
  AL = L(:,2);
%
%  Record the first appearance of each node.
% 
  k = 1;
  AP(1) = k;
  node = 1;

  for edge = 1 : edge_num
    while ( L(edge,1) ~= node )
      node = node + 1;
      AP(node) = edge;
    end
  end
  node = node + 1;
  AP(node) = edge_num + 1;
  
  return
end

