      SUBROUTINE SORT(A,L,N)
c
c this is a fortran version of a routine designed by KNUTH
c Sorting and Searching, page 167 and onwards
c sorting time is proportional to log(n)
c Output is a linked list  l   =L(l ), actual index is l -1.
c                           k+1    k                    k
c
      DIMENSION A(1),L(1)
      J=N-1
      DO 10 I=2,J
      L(I)=-(I+2)
   10 CONTINUE
      L(N+1)=0
      L(N)=0
      L(1)=2
      L(N+2)=3
  110 IS=1
      IT=N+2
      IP=L(IS)
      IQ=L(IT)
      IF(IQ.EQ.0) RETURN
  160 IF(A(IP-1).GT.A(IQ-1)) GOTO 240
  170 L(IS)=ISIGN(IP,L(IS))
      IS=IP
      IP=L(IP)
      IF(IP) 200,200,160
  200 L(IS)=IQ
      IS=IT
  210 IT=IQ
      IQ=L(IQ)
      IF(IQ) 300,300,210
  240 L(IS)=ISIGN(IQ,L(IS))
      IS=IQ
      IQ=L(IQ)
      IF(IQ) 270,270,160
  270 L(IS)=IP
      IS=IT
  280 IT=IP
      IP=L(IP)
      IF(IP) 300,300,280
  300 IP=-IP
      IQ=-IQ
      IF(IQ) 160,320,160
  320 L(IS)=ISIGN(IP,L(IS))
      L(IT)=0
      GOTO 110
      END
ity.
  The author welcomes suggestions and improvements, and would like
  to receive floppy disks with ex