C
C ________________________________________________________
C | |
C | SORT AN ARRAY IN INCREASING ORDER |
C | |
C | INPUT: |
C | |
C | X --ARRAY OF NUMBERS |
C | |
C | Y --WORKING ARRAY (LENGTH AT LEAST N) |
C | |
C | N --NUMBER OF ARRAY ELEMENTS TO SORT |
C | |
C | OUTPUT: |
C | |
C | X --SORTED ARRAY |
C |________________________________________________________|
C
SUBROUTINE SORT(X,Y,N)
REAL X(1),Y(1),S,T
INTEGER I,J,K,L,M,N
I = 1
10 K = I
20 J = I
I = I + 1
IF ( J .EQ. N ) GOTO 30
IF ( X(I) .GE. X(J) ) GOTO 20
Y(K) = I
GOTO 10
30 IF ( K .EQ. 1 ) RETURN
Y(K) = N + 1
40 M = 1
L = 1
50 I = L
IF ( I .GT. N ) GOTO 120
S = X(I)
J = Y(I)
K = J
IF ( J .GT. N ) GOTO 100
T = X(J)
L = Y(J)
X(I) = L
60 IF ( S .GT. T ) GOTO 70
Y(M) = S
M = M + 1
I = I + 1
IF ( I .EQ. K ) GOTO 80
S = X(I)
GOTO 60
70 Y(M)= T
M = M + 1
J = J + 1
IF ( J .EQ. L ) GOTO 110
T = X(J)
GOTO 60
80 Y(M) = T
K = M + L - J
I = J - M
90 M = M + 1
IF ( M .EQ. K ) GOTO 50
Y(M) = X(M+I)
GOTO 90
100 X(I) = J
L = J
110 Y(M) = S
K = M + K - I
I = I - M
GOTO 90
120 I = 1
130 K = I
J = X(I)
140 X(I) = Y(I)
I = I + 1
IF ( I .LT. J ) GOTO 140
Y(K) = I
IF ( I .LE. N ) GOTO 130
IF ( K .EQ. 1 ) RETURN
GOTO 40
END