C
C THIS ROUTINE IS A DEMOSTRATION OF A SHELL SORT
C
	INTEGER	T,A,D,FLAG,TIME(6),DATE(6),START,END
	DIMENSION A(2000)
	TYPE 'Shell sort'
	TYPE
C
C GET HOW MANY NUMBERS TO SORT
C
88	ACCEPT 'How many numbers (2-2000) ',NN
	IF (NN .LT. 2.OR.NN .GT. 2000)STOP
C
C GENERATE ARRAY OF NUMBERS TO SORT
C
	DO 10 I=1,NN
10	A(I)=(RAND(0)*NN)+1
	TYPE 'Starting sort'
	D=NN
	FLAG=0
C
100	D=IFIX((D+1)/2)
C
C TYPE OUT INTERMEDIATE	STUFF
C
	TYPE 'D=',D
C
110	ND=NN-D
	DO 150 N=1,ND
	IF (A(N) .LE. A(N+D))GO	TO 150
	NPD=N+D
	T=A(N)
	A(N)=A(NPD)
	A(NPD)=T
	FLAG=1
C
150	CONTINUE
	IF (FLAG .EQ. 1)THEN
			FLAG=0
			GO TO 110
			ENDIF
	IF (D .GT. 1)GO	TO 100
	TYPE 'All done'
	TYPE
C
C TYPE OUT SORTTED ARRAY
C
	TYPE (A(I),I=1,NN)
	GO TO 88
	END
ENDIF
	IF (D .GT. 1)GO	TO 100
	TYPE 'All done'
	TYPE
C
C TYPE OUT SORTTED ARRAY
C
	TYPE (A(I),I=1,NN)
	GO TO 8