function x = c8vec_sort_a_li ( n, x )

%*****************************************************************************80
%
%% c8vec_sort_a_li() ascending sorts a C8VEC by Loo norm.
%
%  Discussion:
%
%    The Loo norm of A+Bi is max ( abs ( A ) , abs ( B ) ).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 September 2006
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of entries in the array.
%
%    complex X(N), an unsorted array.
%
%  Output:
%
%    complex X(N), the sorted array.
%
  if ( n <= 1 )
    return
  end

  i = 0;
  indx = 0;
  isgn = 0;
  j = 0;

  while ( true )

    [ indx, i, j ] = sort_heap_external ( n, indx, isgn );

    if ( 0 < indx )

      temp = x(i);
      x(i) = x(j);
      x(j) = temp;

    elseif ( indx < 0 )

      if ( c8_le_li ( x(i), x(j) ) )
        isgn = -1;
      else
        isgn = +1;
      end

    elseif ( indx == 0 )

      break

    end

  end 

  return
end
