	INTEGER A0(2), A(15000), STACK(60,2)
	INTEGER L,R,I,J,M,S,V,T
	EQUIVALENCE (A0(2),A(1))

	DO 10 I= 1,15000
10	A(I)= MOD(I,500)
	A0(1)= -32767

	S=1
	STACK(1,1)=1
	STACK(1,2)= 15000
C	UNSTACK AND PARTITION NEXT SUBLIST
20	L= STACK(S,1)
	R= STACK(S,2)
	S= S-1
25	IF (R-L .LE. 20) GOTO 1000
	M= (L+R)/2
	T= A(M)
	A(M)=A(L+1)
	A(L+1)=T
	IF (A(L+1) .LE. A(R)) GOTO 30
	T=A(L+1)
	A(L+1)=A(R)
	A(R)=T
30	IF (A(L) .LE. A(R)) GOTO 40
	T=A(L)
	A(L)=A(R)
	A(R)=T
40	IF (A(L+1) .LE. A(L)) GOTO 50
	T=A(L+1)
	A(L+1)=A(L)
	A(L)=T

50	I=L+1
	J=R
	V=A(L)
100	I=I+1
	IF (A(I) .LT. V) GOTO 100
200	J=J-1
	IF (A(J) .GT. V) GOTO 200
	IF (I .GE. J) GOTO 300
	T=A(I)
	A(I)=A(J)
	A(J)=T
300	IF (I .LE. J) GOTO 100
	A(L)=A(J)
	A(J)=V
	S=S+1
	IF ((I-L) .LT. (R-I)) GOTO 400
	STACK(S,1)=L
	STACK(S,2)=J-1
	L=I
	GOTO 25
400	STACK(S,1)=I
	STACK(S,2)=R
	R=J-1
	GOTO 25

1000	IF (S .GT. 0) GOTO 20

C	INSERTION SORT
	DO 1900 L=1,14999
1100	IF (A(L) .LE. A(L+1)) GOTO 1900
	V=A(L+1)
	J=L
1200	A(J+1)=A(J)
	J=J-1
	IF (A(J) .GT. V) GOTO 1200
	A(J+1)=V

1900	CONTINUE

	END
