Skip to content
Snippets Groups Projects
isorti_sloan.f 1.43 KiB
Newer Older
  • Learn to ignore specific revisions
  • Douglas Guptill's avatar
    Douglas Guptill committed
          SUBROUTINE ISORTI_SLOAN(NL,LIST,NK,KEY)
    ************************************************************************
    *
    *     PURPOSE:
    *     --------
    *
    *     Order a list of integers in ascending sequence of their keys 
    *     using insertion sort
    *
    *     INPUT:
    *     ------
    *
    *     NL   - Length of LIST
    *     LIST - A list of integers
    *     NK   - Length of KEY (NK must be ge NL)
    *     KEY  - A list of integer keys
    *
    *     OUTPUT:
    *     -------
    *
    *     NL   - Unchanged
    *     LIST - A list of integers sorted in ascending sequence of KEY
    *     NK   - Unchanged
    *     KEY  - Unchanged
    *
    *     NOTE:    Efficient for short lists only (NL lt 20)
    *     -----
    *
    *     PROGRAMMER:             Scott Sloan
    *     -----------
    *
    *     LAST MODIFIED:          1 March 1991     Scott Sloan
    *     --------------
    *
    *     COPYRIGHT 1989:         Scott Sloan
    *     ---------------         Department of Civil Engineering
    *                             University of Newcastle
    *                             NSW 2308
    *
    ************************************************************************
          INTEGER I,J,T
          INTEGER NL,NK
          INTEGER VALUE
          INTEGER KEY(NK)
          INTEGER LIST(NL)
    *
          DO 20 I=2,NL
            T=LIST(I)
            VALUE=KEY(T)
            DO 10 J=I-1,1,-1
               IF(VALUE.GE.KEY(LIST(J)))THEN
                 LIST(J+1)=T
                 GOTO 20
               ENDIF
               LIST(J+1)=LIST(J)
       10   CONTINUE
            LIST(1)=T
       20 CONTINUE
          END