      LOGICAL FUNCTION NXTPRM(NUMS, N)
      IMPLICIT NONE

      INTEGER I, II, J, N
      INTEGER TEMP
      INTEGER NUMS(*)

      IF (N .LE. 1) THEN
         NXTPRM = .FALSE.
         RETURN
      END IF
      
      I = N

 10   II = I
      I = I - 1
      IF (NUMS(I) .LT. NUMS(II)) THEN
         J = N
 20      IF (NUMS(I) .GE. NUMS(J)) THEN
            J = J - 1
            GOTO 20
         END IF
         TEMP = NUMS(I)
         NUMS(I) = NUMS(J)
         NUMS(J) = TEMP
         J = N
 30      IF (II .LT. J) THEN
            TEMP = NUMS(II)
            NUMS(II) = NUMS(J)
            NUMS(J) = TEMP
            II = II + 1
            J = J - 1
            GOTO 30
         END IF
         NXTPRM = .TRUE.
         RETURN
      END IF
      IF (I .EQ. 1) THEN
         II = I
         J = N
 40      IF (II .LT. J) THEN
            TEMP = NUMS(II)
            NUMS(II) = NUMS(J)
            NUMS(J) = TEMP
            II = II + 1
            J = J - 1
            GOTO 40
         END IF
         NXTPRM = .FALSE.
         RETURN
      END IF
      GOTO 10

      END
